chair ring
JavaScript performance comparison
Info
go around a ring of 100 removing every second chair (starting at the first chair)
This is a look to see how an array based solution would do against a custom data structure.
Preparation code
<script>
Benchmark.prototype.setup = function() {
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp */)
{
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
{
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t))
res.push(val);
}
}
return res;
};
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
array |
|
pending… |
custom data structure |
|
pending… |
array sol'n 2 |
|
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
- Revision 2: published
- Revision 3: published
- Revision 4: published by Rhys
- Revision 5: published by Jon-Carlos Rivera
- Revision 6: published
- Revision 7: published
- Revision 8: published by Rhys
- Revision 9: published
- Revision 10: published by Jon-Carlos Rivera
- Revision 11: published by Jon-Carlos Rivera
- Revision 12: published by Der Humph
- Revision 13: published by Der Humph
0 comments