Created
December 22, 2011 18:47
-
-
Save kevinohara80/1511377 to your computer and use it in GitHub Desktop.
Javascript eval() benchmark
This file contains 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
/* Test Eval */ | |
var eval_string = 'var x = 1;' | |
+ 'if(x >= 1) {' | |
+ ' var y = x * 2;' | |
+ ' if(y==3) { y=3; }' | |
+ '}'; | |
var eval_start = (new Date()).getTime(); | |
for(var i=0; i<1000000; i++) { | |
eval(eval_string); | |
} | |
var eval_end = (new Date()).getTime(); | |
var eval_diff = (eval_end - eval_start); | |
console.log('eval time -> ' + (eval_diff/1000) + ' seconds'); | |
/* Test normal js */ | |
var js_start = (new Date()).getTime(); | |
for(var i=0; i<1000000; i++) { | |
var x = 1; | |
if(x >= 1) { | |
var y = x * 2; | |
if(y==3) { y=4; } | |
} | |
} | |
var js_end = (new Date()).getTime(); | |
var js_diff = (js_end - js_start); | |
console.log('js time -> ' + (js_diff/1000) + ' seconds'); |
This file contains 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
node benchmark.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment