0

i wrote a Jquery foreach loop through a object. IE takes 15.8ms to execute the code whereas Chrome takes 1.164ms to execute the code. what change i need to do so that in IE it runs faster??

$.each(prefs.ResultColumnPreferences, function (key, value) {
    if (value.IsLPID) {
        headerRow.append($("<th/>").text(prefs.ResultColumnPreferences[i].DisplayName + "LPID"));
        hideList.push(headerRow.children().length - 1);
    }
    else if (value.IsMultivalue) {
        headerRow.append($("<th/>").text(prefs.ResultColumnPreferences[i].DisplayName + "Multivalue"));
        hideList.push(headerRow.children().length - 1);
    }
    headerRow.append($("<th/>").text(value.DisplayName));
    if (!value.IsVisible) {
        hideList.push(headerRow.children().length - 1);
    }

    if (prefs.SortBy === value.PropertyName) {
        if (prefs.SortOrder === 1) {
            orderList = [[headerRow.children().length - 1, "asc"]];
        }
        else {
            orderList = [[headerRow.children().length - 1, "desc"]];
        }
    }


});
Rani
  • 111
  • 1
  • 2
  • 10
  • Hey someone answered here: https://stackoverflow.com/questions/6570053/jquery-very-slow-in-ie?lq=1 – ali 6e7 Aug 22 '18 at 20:36

1 Answers1

0

While browser performance is a cause for concern, performance can differ wildly between browsers; however, its generally not a factor of ten different.

jQuery was designed to shore-up differences between browser DOM access. Differences in completing the same task in different browser should come as no surprise; however this may differ from version to version of jQuery.

One solution is to debug jQuery, step by step, and identify which lines are costing you the most as some things are a function of the browser, and some of them a function of the library.

Another solution is just to use the native Array.forEach which may improve some performance differences.

Adam Hess
  • 1,396
  • 1
  • 13
  • 28