Guest User

v8 method inlining

a guest
Jul 19th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Foobar() {
  2.     this.abc = 1;
  3.     this.test = function (n) {
  4.         this.abc = n;
  5.     };
  6.     this.runTest = function (N) {
  7.         console.time('foobar speed');
  8.         for (var i = 0; i < N; ++i) {
  9.             this.test(i);
  10.         }
  11.         console.timeEnd('foobar speed');
  12.     };
  13. }
  14.  
  15. var N = 10000000;
  16. var a = new Foobar(), b = new Foobar(), c = new Foobar();
  17. a.runTest(N); // foobar speed: 18ms
  18. b.runTest(N); // foobar speed: 125ms
  19. c.runTest(N); // foobar speed: 122ms
  20. a.runTest(N); // foobar speed: 14ms
  21. b.runTest(N); // foobar speed: 117ms
  22. c.runTest(N); // foobar speed: 128ms
Advertisement
Add Comment
Please, Sign In to add comment