How to Benchmark Javascript DOM Manipulation -


i have 2 javascript functions same thing: create menu based on json object.

one function appends <ul> , <li> elements variable, , writes html document using method innerhtml

the second function create dom elements through createelement("ul") , appendchild() methods

so want know function faster, not know how perform benchmark test in javascript.

my first function buildmenutostring() , second function buildmenudom()

i use this:

var bench = function(fn, iterations){         var time = 0, = 0, total;          // start         time = +(new date);          while(i < iterations){           fn.apply();           i++;         }          total = +(new date) - time;          console.log("mean exec time: ", total / iterations, 'ms');         console.log("sum exec time: ", total, 'ms');      }; 

example:

var test1 = function(){       $('body').append('<div />');        },      test2 = function(){        div = document.createelement('div');        document.body.appendchild(div);     };  bench(test1, 1000); bench(test2, 1000); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -