array loop var caching
JavaScript performance comparison
Info
Testing speed between array index searching and variable reference.
Data set contains 5000 elements.
Test performs 200 operations with a single index
Preparation code
<script>
Benchmark.prototype.setup = function() {
var data = [];
var x = new Date();
for (var i = 0; i < 5000; i++) {
data.push(x.getTime());
}
};
Benchmark.prototype.teardown = function() {
var data = null;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
using index |
|
pending… |
caching index |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments