Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Speed of jQuery and Prevel Framework in comparison.
- // In each test jQuery and Prevel starts in turn.
- // Tasks are completely equal.
- // Data has been obtained by working with the DOM tree consists of 1536 elements.
- // Prevel (jQuery, too) works with all the found elements.
- window.onload = function() {
- // Looking for elements in the DOM
- // Prevel: 3ms
- // jQuery: 9ms
- console.group('pl() / $()');
- console.time('Prevel');
- pl('div');
- pl('*', 'body');
- pl('.post .post_image');
- pl('.post_image', '.post');
- pl('.post_image', '.post', 0);
- console.timeEnd('Prevel');
- console.time('jQuery');
- $('div');
- $('*', 'body');
- $('.post .post_image');
- $('.post_image', '.post');
- $('.post_image', '.post').eq(0);
- console.timeEnd('jQuery');
- console.groupEnd();
- // Working with element's HTML
- // jQuery: 3ms
- // Prevel: 1ms
- console.group('pl().html() / $().html()');
- console.time('jQuery');
- $('.post_image', '.post').html();
- $('.post_image', '.post').html('image');
- console.timeEnd('jQuery');
- console.time('Prevel');
- pl('.post_image', '.post').html();
- pl('.post_image', '.post').html('image');
- console.timeEnd('Prevel');
- console.groupEnd();
- // Working with attributes
- // Prevel: 21ms
- // jQuery: 33ms
- console.group('pl().attr() / $().attr()');
- console.time('Prevel');
- pl('div').attr('id');
- pl('div').attr('data-localStorage', Math.PI);
- pl('*', 'body').attr({
- 'data-localStorage': Math.PI,
- 'class': 'PrevelFramework'
- });
- pl('*', 'body').attr('data-localStorage');
- console.timeEnd('Prevel');
- console.time('jQuery');
- $('div').attr('id');
- $('div').attr('data-localStorage', Math.PI);
- $('*', 'body').attr({
- 'data-localStorage': Math.PI,
- 'class': 'PrevelFramework'
- });
- $('*', 'body').attr('data-localStorage');
- console.timeEnd('jQuery');
- console.groupEnd();
- // Working with CSS
- // jQuery: 117ms
- // Prevel: 46ms
- console.group('pl().css() / $().css()');
- console.time('jQuery');
- $('div').css('display', 'inline');
- $('div').css('display');
- $('*', 'body').css({
- 'margin-left': 20,
- marginTop: 15,
- filter: 'alpha(opacity=100)'
- });
- $('*', 'body').css('opacity');
- console.timeEnd('jQuery');
- console.time('Prevel');
- pl('div').css('display', 'inline');
- pl('div').css('display');
- pl('*', 'body').css({
- 'margin-left': 20,
- marginTop: 15,
- filter: 'alpha(opacity=100)'
- });
- pl('*', 'body').css('opacity');
- console.timeEnd('Prevel');
- console.groupEnd();
- // Add an event listener to all the found elements
- // Prevel: 9ms
- // jQuery: 18ms
- console.group('pl().bind() / $().bind()');
- console.time('Prevel');
- pl('div').bind('click', function() {
- pl(this).css('border', '1px solid red');
- });
- console.timeEnd('Prevel');
- console.time('jQuery');
- $('div').bind('click', function() {
- $(this).css('border', '1px solid red');
- });
- console.timeEnd('jQuery');
- console.groupEnd();
- };
Add Comment
Please, Sign In to add comment