jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope says
Functions defined by function expressions and function declarations are parsed only once, while those defined by the Function constructor are not. That is, the function body string passed to the Function constructor must be parsed every time it is evaluated. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than "new Function(...)". Therefore the Function constructor should be avoided whenever possible.
Which sounds bad.
<script>
function fNormal() {for(var i=0,a=0; i<1000; i++) {a += 1;}}
var fStatic = function() {for(var i=0,a=0; i<1000; i++) {a += 1;}},
fCtor = new Function('for(var i=0,a=0; i<1000; i++) {a += 1};');
eval('var fEval = function() {for(var i=0,a=0; i<1000; i++) {a += 1}};');
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Function expression |
| ready |
Function constructor |
| ready |
A function created with eval() |
| ready |
A function created the "normal" way |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.