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
I created this page to test the performance variation of a certain function with and without eval.
var x = '0', y = '1';
evalTest = function (x, y) {
'use strict';
// Match any character except: digits (0-9), dash (-), period (.), or backslash (/) and replace those characters with empty string.
x = x.replace(/[^\d\-\.\/]/g, '');
y = y.replace(/[^\d\-\.\/]/g, '');
// Handle simple fractions
if (x.indexOf('/') >= 0) {
x = eval(x);
}
if (y.indexOf('/') >= 0) {
y = eval(y);
}
return x - y;
};
newEvalTest = function (x, y) {
'use strict';
// Match any character except: digits (0-9), dash (-), period (.), or backslash (/) and replace those characters with empty string.
x = x.replace(/[^\d\-\.\/]/g, '');
y = y.replace(/[^\d\-\.\/]/g, '');
// Handle simple fractions
if (x.indexOf('/') >= 0) {
x = (1,eval)(x);
}
if (y.indexOf('/') >= 0) {
y = (1,eval)(y);
}
return x - y;
};
notEvalTest = function (x, y) {
'use strict';
// Define vars
var a = [], b = [];
// Match any character except: digits (0-9), dash (-), period (.), or backslash (/) and replace those characters with empty string.
x = x.replace(/[^\d\-\.\/]/g, '');
y = y.replace(/[^\d\-\.\/]/g, '');
// Handle simple fractions
if (x.indexOf('/') >= 0) {
a = x.split("/");
x = parseInt(a[0], 10) / parseInt(a[1], 10);
}
if (y.indexOf('/') >= 0) {
b = y.split("/");
y = parseInt(b[0], 10) / parseInt(b[1], 10);
}
return x - y;
};
Ready to run.
Test | Ops/sec | |
---|---|---|
eval |
| ready |
NOT eval |
| ready |
New Eval |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.