getHash
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var testObject = {theNumber: 42};
var objectId = 1000000;
getHash1 = function(value) {
if (typeof value === 'number' || typeof value === 'boolean') {
return value;
} else if (typeof value === 'string') {
return '"' + value + '"';
} else if (value === undefined) {
return 'undefined';
} else if (value === null) {
return 'null';
} else {
value._hash = value._hash || ('[object ' + (objectId++) + ']');
return value._hash;
}
}
function getHash2(value) {
if (typeof value === 'object') {
if (value === null)
return 'null';
value._hash = value._hash || ('[object ' + (objectId++) + ']');
return value._hash;
}
if (typeof value === 'string')
return "'" + value;
return '' + value;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Original getHash() |
|
pending… |
Modified getHash() |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments