Hi folks-

I am getting some troublesome benchmarks on a bit of code and I wonder
if I am missing something.  I am iterating over a JSON object to
dynamically create a menu.  The jQuery code consistently takes over
5000 milliseconds (!) to complete and my raw javascript version
consistently takes less than 500 milliseconds.  That means jQuery is
more than 10 times slower for this code than raw javascript.

I am including all of the code (both raw javascript and jQuery
versions) as well as the sample JSON data that I used.

any help/advice would be appreciated.

-Peter Keane

var tags={};  //used by basic javascript version
tags['tagsSelect'] = document.getElementById('tagsSelect'); //used by
basic javascript version

var start = new Date();

for (var type in json[eid]) {
  for (var ascii in json[eid][type]) {

/* basic javascript version  */

 tags['tagsSelect'].innerHTML = tags['tagsSelect'].innerHTML + "<input
type='checkbox' name='" + ascii + "'> " + json[eid][type][ascii] + "</
input><br>\n";
 tags[type] = tags[type] ? tags[type] : document.getElementById(type);
 if (tags[type]) {
   tags[type].innerHTML = tags[type].innerHTML + "<li><a href='" + eid
+ "/tag/" + ascii + "'>" + json[eid][type][ascii] + "</a></li>\n";
 }

/*  jQuery version */

var all = $("#tagsSelect").html() + "<input type='checkbox' name='" +
ascii + "'> " + json[eid][type][ascii] + "</input><br>\n";
  $("#tagsSelect").html(all);
  var html = $("#" + type).html() + "<li><a href='" + eid + "/tag/" +
ascii + "'>" + json[eid][type][ascii] + "</a></li>\n";
 $("#" + type).html(html);
                */

  }
}

var end = new Date();
alert(end - start); //display execution time in milliseconds


Here is the JSON:

{"pkeane":
  {
     "slideshow":
     {"educause_no_1":"educause no 1","educause_slides":"educause
slides","educause_backups":"educause backups","saved_images":"saved
images","tcdl":"tcdl","test_tcdl":"test tcdl","top_hats":"top
hats","zoom":"zoom","tddp_mockup":"tddp mockup","tgdp_mocks":"tgdp
mocks","dase_workshop":"dase workshop"},
     "user_collection":
     {"test_20":"test","rebuild_this":"rebuild
this!","blues_1":"blues_1","new_test":"new test","ok_new_semester":"ok
new semester","ssss":"ssss","matisse":"matisse","ben_shahn":"ben
shahn"},"cart":{"keanepj":"My Cart"},
     "subscription":
     {"texas_politics_feature_of_the_week":"Texas Politics Feature of
the
Week","aeneid7_8":"Aeneid7-8","agamemnon":"Agamemnon","rome_day_1":"Rome
day 1","alor_charts":"alor charts","frank_lloyd_wright":"Frank Lloyd
Wright","tigerfeed":"tigerFeed","clarke_alor_3_1":"Clarke, ALOR 3"
     }
   }
}

Reply via email to