Multiple shift vs slice

JavaScript performance comparison

Test case created by Multiple shift vs slice

Info

Scaling array down to accepted size, which is faster. Multiple shifts, or a single slice

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var org = [];
    var scaleTo = 50;
    for (var i = 0; i < 100; i++) {
      org.push(i);
    }
};

Benchmark.prototype.teardown = function() {
    org = []
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
MultipleShifts
while (org.length > scaleTo) {
  org.shift()
}
pending…
Slice
var slen = org.length - scaleTo;
org = org.slice(slen)
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment