eval test
JavaScript performance comparison
Info
I created this page to test the performance variation of a certain function with and without eval.
Preparation code
<script>
Benchmark.prototype.setup = function() {
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;
};
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;
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
eval |
|
pending… |
NOT eval |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by JP Grace
- Revision 2: published by Praneet Loke
0 comments