simulate range of python

JavaScript performance comparison

Test case created by kerryChen95

Preparation code

<script src="https://raw.github.com/documentcloud/underscore/1.4.4/underscore.js"></script>
<script>
function arrayApplyAndMap (start, end, step) {
  if (arguments.length <= 1) {
    end = start || 0;
    start = 0;
  }
  step = step || 1;
  return Array.apply(null, new Array( Math.max(Math.ceil( (end - start) / step ), 0) )).map(function (val, i) { return i * step + start; });
};

var underscore1_4_4 = _.range;

var longLengthSmallStep = [1, 10000, 1];
var longLengthLargeStep = [1, 10000, 1000];
var shortLength = [1, 5];
</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
array apply and map
arrayApplyAndMap.apply(null, longLengthSmallStep);
arrayApplyAndMap.apply(null, longLengthLargeStep);
arrayApplyAndMap.apply(null, shortLength);
pending…
underscore1.4.4
underscore1_4_4.apply(null, longLengthSmallStep);
underscore1_4_4.apply(null, longLengthLargeStep);
underscore1_4_4.apply(null, shortLength);
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:

0 comments

Add a comment