Created
December 12, 2014 15:02
-
-
Save dazld/2a5dc58f5c9ce61bccae to your computer and use it in GitHub Desktop.
js inline cache benchmark node 0.10.33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mb:scratch danpeddle$ node --version | |
v0.10.33 | |
mb:scratch danpeddle$ node test.js | |
no comments x 9,705,374 ops/sec ±1.14% (92 runs sampled) | |
short comment x 9,876,201 ops/sec ±0.85% (93 runs sampled) | |
long comments x 9,802,210 ops/sec ±1.14% (86 runs sampled) | |
Fastest is short comment,long comments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Benchmark = require('benchmark'); | |
function f1(a, b){ | |
return a + b; | |
} | |
function f2(a, b){ | |
/* Aliquam malesuada tortor justo, sed euismod diam varius a.*/ | |
return a + b; | |
} | |
function f3(a, b){ | |
/* Aliquam malesuada tortor justo, sed euismod diam varius a. Aliquam non risus orci. Duis et varius orci. Phasellus sit amet enim sed erat laoreet dapibus. Etiam ullamcorper nisi maximus elit suscipit, a aliquam velit vehicula. Suspendisse feugiat nibh quis elit aliquet eleifend. In hac habitasse platea dictumst. Maecenas risus sapien, venenatis sed lectus sit amet, rutrum consequat orci. Maecenas egestas enim in velit consequat, accumsan condimentum tortor iaculis. Praesent quis rhoncus eros. Ut ornare malesuada porta. Suspendisse volutpat semper ex eu varius. */ | |
return a + b; | |
} | |
var suite = new Benchmark.Suite; | |
//add tests | |
suite.add('no comments', function() { | |
var sum = 0; | |
for(var i=0; i<100; i++){ | |
sum = f1(sum, i); | |
} | |
}) | |
.add('short comment', function() { | |
var sum = 0; | |
for(var i=0; i<100; i++){ | |
sum = f2(sum, i); | |
} | |
}) | |
.add('long comments', function(){ | |
var sum = 0; | |
for(var i=0; i<100; i++){ | |
sum = f3(sum, i); | |
} | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | |
}) | |
// run async | |
.run({ 'async': true }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment