Template.prototype.changePreviewTexts

Benchmark created by George Sfitis on


Setup

var elements_arr = ['title','description','action_button'],
      attrs_arr    = ['font-size'],
      style        = {
          title: { 'real-font-size': '32px' },
          description: { 'real-font-size': '32px' },
          action_button: { 'real-font-size': '32px' },
      },
      percentageDifference = 0.4;

Test runner

Ready to run.

Testing in
TestOps/sec
Duble forEach uncached arrays
['title','description','action_button'].forEach(function(element,i){

    ['font-size'].forEach(function(attr,i){

        style[element][attr] = parseInt(parseInt(style[element]['real-'+attr]) * percentageDifference) + 'px';

    });

});
ready
Duble forEach cached arrays
elements_arr.forEach(function(element,i){

    attrs_arr.forEach(function(attr,i){

        style[element][attr] = parseInt(parseInt(style[element]['real-'+attr]) * percentageDifference) + 'px';

    });

});
ready
Outer for uncached length
for (var i = 0; i < elements_arr.length; i++) {

    ['font-size'].forEach(function(attr,i){

        style[elements_arr[i]][attr] = parseInt(parseInt(style[elements_arr[i]]['real-'+attr]) * percentageDifference) + 'px';

    });

}
ready
Outer for cached length
var elements_length   = elements_arr.length;
for (var i = 0; i < elements_length; i++) {

    ['font-size'].forEach(function(attr,i){

        style[elements_arr[i]][attr] = parseInt(parseInt(style[elements_arr[i]]['real-'+attr]) * percentageDifference) + 'px';

    });

}
ready
Both for cached length
var elements_length   = elements_arr.length,
    attrs_length      = attrs_arr.length;
    
for (var i = 0; i < elements_length; i++) {

    for (var j = 0; j < attrs_length; j++) {
        
        style[elements_arr[i]][attrs_arr[j]] = parseInt(parseInt(style[elements_arr[i]]['real-'+attrs_arr[j]]) * percentageDifference) + 'px';
        
    }

}
ready
Both for uncached length
for (var i = 0; i < elements_arr.length; i++) {

    for (var j = 0; j < attrs_arr.length; j++) {
        
        style[elements_arr[i]][attrs_arr[j]] = parseInt(parseInt(style[elements_arr[i]]['real-'+attrs_arr[j]]) * percentageDifference) + 'px';
        
    }

}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by George Sfitis on