Comparison of numbers

JavaScript performance comparison

Test case created by Rob W


See: <a target="_blank" href=""></a>

Preparation code

Benchmark.prototype.setup = function() {
    var myArray =
        {"ID": 1, "Cost": 200},
        {"ID": 2, "Cost": 1000},
        {"ID": 3, "Cost": 50},
        {"ID": 4, "Cost": 500}

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Rob W
var lowest = Number.POSITIVE_INFINITY;
var highest = Number.NEGATIVE_INFINITY;
var tmp;
for (var i=myArray.length-1; i>=0; i--) {
    tmp = myArray[i].Cost;
    if (tmp < lowest) lowest = tmp;
    if (tmp > highest) highest = tmp;
function finder(cmp, arr, attr) {
    var val = arr[0][attr];
    for(var i=1;i<arr.length;i++) {
        val = cmp(val, arr[i][attr]);
    return val;

var highest = finder(Math.max, myArray, "Cost");
var lowest = finder(Math.min, myArray, "Cost");
32bitkid, optimized
var highest = myArray[0].Cost;
var lowest = myArray[0].Cost;
for(var i=1;i<myArray.length;i++) {
    highest = Math.max(highest, myArray[i].Cost);
    lowest = Math.min(lowest, myArray[i].Cost);

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment