switch
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = 0,
b = 1,
c = 0,
d = -1;
var arr = [0, 1, 0, -1];
function switchGetVal(i) {
switch (i) {
case 0:
return a;
case 1:
return b;
case 2:
return c;
case 3:
return d;
default:
return null;
}
}
function arrayGetVal(i) {
return arr[i];
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
switch access |
|
pending… |
array access |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments