dynamic or fixed
JavaScript performance comparison
Info
Testing dynamic arrays vs fixed length arrays, inspiration from Alex Gaynor's talk: https://speakerdeck.com/alex/why-python-ruby-and-javascript-are-slow
Preparation code
<script>
Benchmark.prototype.setup = function() {
function square(n) {
var ret = [];
for (var i=0; i<n; i++) {
ret[i] = i*i;
}
return ret;
}
function square2(n) {
var ret = new Array(n);
for (var i=0; i<n; i++) {
ret[i] = i*i;
}
return ret;
}
function square3(n) {
var buffer = new ArrayBuffer(n*4);
var int32View = new Uint32Array(buffer);
for (var i=0; i<n; i++) {
int32View[i] = i*i;
}
return int32View;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
dynamic length |
|
pending… |
fixed lenght |
|
pending… |
typed arrays |
|
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 quimcalpe and last updated
- Revision 3: published
0 comments