jquery performance test selectors


/ Published in: jQuery
Save to your folder(s)

jquery performance test see also http://jsbin.com/aciji4/12


Copy this code and paste it in your HTML
  1. var loops = 1000;
  2.  
  3. console.time('simple');
  4. for(i = 0; i < loops; i++){
  5. var x = $('option[value=valInField]');
  6. }
  7. console.timeEnd('simple')
  8.  
  9. console.time('selectorcontext');
  10. for(i = 0; i < loops; i++){
  11. var x = $('#critRow_0 option[value=valInField]');
  12. }
  13. console.timeEnd('selectorcontext')
  14.  
  15. console.time('findcontext1');
  16. var context = $('#critRow_0');
  17. for(i = 0; i < loops; i++){
  18. var x = context.find('option[value=valInField]');
  19. }
  20. console.timeEnd('findcontext1')
  21.  
  22. console.time('findcontext2');
  23. for(i = 0; i < loops; i++){
  24. var x = $('#critRow_0').find('option[value=valInField]');
  25. }
  26. console.timeEnd('findcontext2')
  27.  
  28. console.time('contextparm');
  29. var ctx = $('#critRow_0')[0];
  30. for(i = 0; i < loops; i++){
  31. var x = $('option[value=valInField]', ctx);
  32. }
  33. console.timeEnd('contextparm')
  34.  
  35. console.log("1. " + context.find('option[value=valInField]').length);
  36. console.log("2. " + $('#critRow_0 option[value=valInField]').length);
  37. console.log("3. " + $('#critRow_0').find('option[value=valInField]').length);
  38. console.log("4. " + $('option[value=valInField]', ctx).length );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.