Guest User

Untitled

a guest
Jan 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. // Speed of jQuery and Prevel Framework in comparison.
  2.  
  3. // In each test jQuery and Prevel starts in turn.
  4. // Tasks are completely equal.
  5. // Data has been obtained by working with the DOM tree consists of 1536 elements.
  6. // Prevel (jQuery, too) works with all the found elements.
  7.  
  8. window.onload = function() {
  9.  
  10. // Looking for elements in the DOM
  11. // Prevel: 3ms
  12. // jQuery: 9ms
  13. console.group('pl() / $()');
  14. console.time('Prevel');
  15. pl('div');
  16. pl('*', 'body');
  17. pl('.post .post_image');
  18. pl('.post_image', '.post');
  19. pl('.post_image', '.post', 0);
  20. console.timeEnd('Prevel');
  21.  
  22. console.time('jQuery');
  23. $('div');
  24. $('*', 'body');
  25. $('.post .post_image');
  26. $('.post_image', '.post');
  27. $('.post_image', '.post').eq(0);
  28. console.timeEnd('jQuery');
  29. console.groupEnd();
  30.  
  31. // Working with element's HTML
  32. // jQuery: 3ms
  33. // Prevel: 1ms
  34. console.group('pl().html() / $().html()');
  35. console.time('jQuery');
  36. $('.post_image', '.post').html();
  37. $('.post_image', '.post').html('image');
  38. console.timeEnd('jQuery');
  39.  
  40. console.time('Prevel');
  41. pl('.post_image', '.post').html();
  42. pl('.post_image', '.post').html('image');
  43. console.timeEnd('Prevel');
  44. console.groupEnd();
  45.  
  46. // Working with attributes
  47. // Prevel: 21ms
  48. // jQuery: 33ms
  49. console.group('pl().attr() / $().attr()');
  50. console.time('Prevel');
  51. pl('div').attr('id');
  52. pl('div').attr('data-localStorage', Math.PI);
  53. pl('*', 'body').attr({
  54. 'data-localStorage': Math.PI,
  55. 'class': 'PrevelFramework'
  56. });
  57. pl('*', 'body').attr('data-localStorage');
  58. console.timeEnd('Prevel');
  59.  
  60. console.time('jQuery');
  61. $('div').attr('id');
  62. $('div').attr('data-localStorage', Math.PI);
  63. $('*', 'body').attr({
  64. 'data-localStorage': Math.PI,
  65. 'class': 'PrevelFramework'
  66. });
  67. $('*', 'body').attr('data-localStorage');
  68. console.timeEnd('jQuery');
  69. console.groupEnd();
  70.  
  71. // Working with CSS
  72. // jQuery: 117ms
  73. // Prevel: 46ms
  74. console.group('pl().css() / $().css()');
  75. console.time('jQuery');
  76. $('div').css('display', 'inline');
  77. $('div').css('display');
  78. $('*', 'body').css({
  79. 'margin-left': 20,
  80. marginTop: 15,
  81. filter: 'alpha(opacity=100)'
  82. });
  83. $('*', 'body').css('opacity');
  84. console.timeEnd('jQuery');
  85.  
  86. console.time('Prevel');
  87. pl('div').css('display', 'inline');
  88. pl('div').css('display');
  89. pl('*', 'body').css({
  90. 'margin-left': 20,
  91. marginTop: 15,
  92. filter: 'alpha(opacity=100)'
  93. });
  94. pl('*', 'body').css('opacity');
  95. console.timeEnd('Prevel');
  96. console.groupEnd();
  97.  
  98. // Add an event listener to all the found elements
  99. // Prevel: 9ms
  100. // jQuery: 18ms
  101. console.group('pl().bind() / $().bind()');
  102. console.time('Prevel');
  103. pl('div').bind('click', function() {
  104. pl(this).css('border', '1px solid red');
  105. });
  106. console.timeEnd('Prevel');
  107.  
  108. console.time('jQuery');
  109. $('div').bind('click', function() {
  110. $(this).css('border', '1px solid red');
  111. });
  112. console.timeEnd('jQuery');
  113. console.groupEnd();
  114. };
Add Comment
Please, Sign In to add comment