/ Published in: jQuery
jquery performance test see also http://jsbin.com/aciji4/12
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var loops = 1000; console.time('simple'); for(i = 0; i < loops; i++){ var x = $('option[value=valInField]'); } console.timeEnd('simple') console.time('selectorcontext'); for(i = 0; i < loops; i++){ var x = $('#critRow_0 option[value=valInField]'); } console.timeEnd('selectorcontext') console.time('findcontext1'); var context = $('#critRow_0'); for(i = 0; i < loops; i++){ var x = context.find('option[value=valInField]'); } console.timeEnd('findcontext1') console.time('findcontext2'); for(i = 0; i < loops; i++){ var x = $('#critRow_0').find('option[value=valInField]'); } console.timeEnd('findcontext2') console.time('contextparm'); var ctx = $('#critRow_0')[0]; for(i = 0; i < loops; i++){ var x = $('option[value=valInField]', ctx); } console.timeEnd('contextparm') console.log("1. " + context.find('option[value=valInField]').length); console.log("2. " + $('#critRow_0 option[value=valInField]').length); console.log("3. " + $('#critRow_0').find('option[value=valInField]').length); console.log("4. " + $('option[value=valInField]', ctx).length );