slowloop

JavaScript performance comparison

Revision 3 of this test case created by Josh

Preparation code

 

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
parsing original
var parseBuylist = function (obj) {

    // Set up vars for product loop
    var len = obj.length;
    var i = 0;

    // Loop thru buylist products returned
    for (i; i < len; i += 1) {

        // Reference to one product
        var product = obj[i];

        // Assign product info to vars
        var name = product['Product Name'];
        var category = product['Category'];
        var price = product['Buy Price'];
        var qty = product['Opt Qty'];

        var link = formatLink(product['URL']);
        var credit = creditPrice(price);

        // Build the markup for each product row
        var markup = '<tr class="item" data-category="' + category + '">';

        // Markup for product name + link
        markup += '<td class="name"><a href="' + link + '" title="' + name + '">' + name + '</a></td>';

        // Marup for category cell
        markup += '<td class="category">' + category + '</td>';

        // Markup for product cash
        markup += '<td class="cash">$' + price + ' USD</td>';

        // Markup for product credit
        markup += '<td class="credit">$' + credit + ' USD</td>';

        // Markup for product qty
        markup += '<td class="qty">' + qty + '</td>';

        // Close table row
        markup += '</tr>';

        jQuery('#buylist-items').append(markup);

    }

};



var creditPrice = function (price) {

    return (parseFloat(price) * 1.3).toFixed(2);

};

var formatLink = function (link) {

    return link.replace(/\/catalog\//, '/buylist/');

};


 
pending…
use array and join after loop
var parseBuylist = function (obj) {

    // Set up vars for product loop
    var markup = '';
    var len = obj.length;
    var i = 0;

    // Loop thru buylist products returned
    for (i; i < len; i += 1) {

        // Reference to one product
        var product = obj[i];

        // Assign product info to vars
        var name     = product['Product Name'];
        var category = product['Category'];
        var price    = product['Buy Price'];
        var qty      = product['Opt Qty'];

        var link     = formatLink(product['URL']);
        var credit   = creditPrice(price);

        // Build the markup for each product row
        markup += '<tr class="item" data-category="' + category + '"><td class="name"><a href="' + link + '" title="' + name + '">' + name + '</a></td><td class="category">' + category + '</td><td class="cash">$' + price + ' USD</td><td class="credit">$' + credit + ' USD</td><td class="qty">' + qty + '</td></tr>';
    }
   
    jQuery('#buylist-items').append(markup);
};

var creditPrice = function (price) {
    var multiplier = 1.3;

    price = parseFloat(price);

    return (price * multiplier).toFixed(2);
};

var formatLink = function (link) {
    return link.replace(/\/catalog\//, '/buylist/');
};


 
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