Real performance of calling methods

Benchmark created by Enzo on


Setup

function mk1(word) {
           var len = word.length;
           if (len > 255) return undefined;
           var i = len >> 2;
           return String.fromCharCode(
               (word.charCodeAt(0) & 0x03) << 14 |
               (word.charCodeAt(i) & 0x03) << 12 |
               (word.charCodeAt(i + i) & 0x03) << 10 |
               (word.charCodeAt(i + i + i) & 0x03) << 8 |
               len
           );
       }
    
       var MK1 = function() {};
       MK1.prototype.mk = mk1;
       var mker1 = new MK1;
       measure1 = {
           'Function': function() {
               var key;
               key = mk1('www.wired.com');
               key = mk1('www.youtube.com');
               key = mk1('scorecardresearch.com');
               key = mk1('www.google-analytics.com');
           },
           'Method': function() {
               var key;
               key = mker1.mk('www.wired.com');
               key = mker1.mk('www.youtube.com');
               key = mker1.mk('scorecardresearch.com');
               key = mker1.mk('www.google-analytics.com');
           }
       };
    
    
    
    
       (function() {
               "Speed" + "you" + "JS" + "with" +
               "this" + "one" + "weird" + "trick";
    
               function mk2(word) {
                   var len = word.length;
                   if (len > 255) return undefined;
                   var i = len >> 2;
                   return String.fromCharCode(
                       (word.charCodeAt(0) & 0x03) << 14 |
                       (word.charCodeAt(i) & 0x03) << 12 |
                       (word.charCodeAt(i + i) & 0x03) << 10 |
                       (word.charCodeAt(i + i + i) & 0x03) << 8 |
                       len
                   );
               }
    
               var MK2 = function() {};
               MK2.prototype.mk = mk2;
               var mker2 = new MK2;
    
               measure2 = {
                   'Function': function() {
                       var key;
                       key = mk2('www.wired.com');
                       key = mk2('www.youtube.com');
                       key = mk2('scorecardresearch.com');
                       key = mk2('www.google-analytics.com');
                   },
                   'Method': function() {
                       var key;
                       key = mker2.mk('www.wired.com');
                       key = mker2.mk('www.youtube.com');
                       key = mker2.mk('scorecardresearch.com');
                       key = mker2.mk('www.google-analytics.com');
                   }
               };
    
       })();

Test runner

Ready to run.

Testing in
TestOps/sec
test1
measure1.Function();
measure1.Method();
 
ready
test2
measure2.Function();
measure2.Method();
ready

Revisions

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