Opal: Method Missing 2

JavaScript performance comparison

Revision 7 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    // the class, the method, and the instance to test
    function Klass () {};
   
    function $mm (name) {}
   
    function rb_send1(recv, mid, arg0) {
      if (recv == null) {
        return dispatch_to_nil();
      }
   
      return (recv[mid] || $mm).call(recv, arg0);
    }
   
    Klass.prototype.method1 = function (arg) { return arg; };
    Klass.prototype.method2 = function (arg) { return arg; };
    Klass.prototype.method3 = function (arg) { return arg; };
    Klass.prototype.method4 = function (arg) { return arg; };
    Klass.prototype.method5 = function (arg) { return arg; };
   
    Klass.prototype.method6 = function (arg) { return arg; };
    Klass.prototype.method7 = function (arg) { return arg; };
    Klass.prototype.method8 = function (arg) { return arg; };
    Klass.prototype.method9 = function (arg) { return arg; };
    Klass.prototype.method0 = function (arg) { return arg; };
   
    Klass.prototype.$m =
    {
    method1: function(self, name, arg){return arg;},
    method2: function(self, name, arg){return arg;},
    method3: function(self, name, arg){return arg;},
    method4: function(self, name, arg){return arg;},
    method5: function(self, name, arg){return arg;},
   
    method6: function(self, name, arg){return arg;},
    method7: function(self, name, arg){return arg;},
    method8: function(self, name, arg){return arg;},
    method9: function(self, name, arg){return arg;},
    method0: function(self, name, arg){return arg;}
    }
   
    var o1 = new Klass();
    var o2 = new Klass();
    var o3 = new Klass();
    var o4 = new Klass();
    var o5 = new Klass();
   
    var o6 = new Klass();
    var o7 = new Klass();
    var o8 = new Klass();
    var o9 = new Klass();
    var o0 = new Klass();
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native
o1.method1(1);
o2.method2(2);
o3.method3(3);
o4.method4(4);
o5.method5(5);

o6.method6(6);
o7.method7(7);
o8.method8(8);
o9.method9(9);
o0.method0(0);
pending…
($mm).call
(o1.method1 || $mm('method1')).call(o1, 1);
(o2.method2 || $mm('method2')).call(o2, 2);
(o3.method3 || $mm('method3')).call(o3, 3);
(o4.method4 || $mm('method4')).call(o4, 4);
(o5.method5 || $mm('method5')).call(o5, 5);

(o6.method6 || $mm('method6')).call(o5, 6);
(o7.method7 || $mm('method7')).call(o6, 7);
(o8.method8 || $mm('method8')).call(o7, 8);
(o9.method9 || $mm('method9')).call(o8, 9);
(o0.method0 || $mm('method0')).call(o0, 0);
pending…
$m
var a1, a2, a3, a4, a5, a6, a7, a8, a9, a0;
(a1 = o1, a1.$m.method1(a1, 'method1', 1));
(a2 = o2, a2.$m.method2(a2, 'method2', 2));
(a3 = o3, a3.$m.method3(a3, 'method3', 3));
(a4 = o4, a4.$m.method4(a4, 'method4', 4));
(a5 = o5, a5.$m.method5(a5, 'method5', 5));

(a6 = o6, a6.$m.method6(a6, 'method6', 6));
(a7 = o7, a7.$m.method7(a7, 'method7', 7));
(a8 = o8, a8.$m.method8(a8, 'method8', 8));
(a9 = o9, a9.$m.method9(a9, 'method9', 9));
(a0 = o0, a0.$m.method0(a0, 'method0', 0));
pending…
($mm)
(o1.method1 || $mm('method1'))(o1, 1);
(o2.method2 || $mm('method2'))(o2, 2);
(o3.method3 || $mm('method3'))(o3, 3);
(o4.method4 || $mm('method4'))(o4, 4);
(o5.method5 || $mm('method5'))(o5, 5);

(o6.method6 || $mm('method6'))(o5, 6);
(o7.method7 || $mm('method7'))(o6, 7);
(o8.method8 || $mm('method8'))(o7, 8);
(o9.method9 || $mm('method9'))(o8, 9);
(o0.method0 || $mm('method0'))(o0, 0);
pending…
(null || $mm).call
(((o1 != null) && o1.method1) || $mm('method1')).call(o1, 1);
(((o2 != null) && o2.method2) || $mm('method1')).call(o2, 2);
(((o3 != null) && o3.method3) || $mm('method1')).call(o3, 3);
(((o4 != null) && o4.method4) || $mm('method1')).call(o4, 4);
(((o5 != null) && o5.method5) || $mm('method1')).call(o5, 5);

(((o1 != null) && o1.method1) || $mm('method1')).call(o1, 1);
(((o2 != null) && o2.method2) || $mm('method1')).call(o2, 2);
(((o3 != null) && o3.method3) || $mm('method1')).call(o3, 3);
(((o4 != null) && o4.method4) || $mm('method1')).call(o4, 4);
(((o5 != null) && o5.method5) || $mm('method1')).call(o5, 5);
pending…
rb_send
rb_send1(o1, 'method1', 1);
rb_send1(o2, 'method2', 2);
rb_send1(o3, 'method3', 3);
rb_send1(o4, 'method4', 4);
rb_send1(o5, 'method5', 5);

rb_send1(o1, 'method1', 1);
rb_send1(o2, 'method2', 2);
rb_send1(o3, 'method3', 3);
rb_send1(o4, 'method4', 4);
rb_send1(o5, 'method5', 5);
pending…
(nul || $mm)
(((o1 != null) && o1.method1) || $mm('method1'))(o1, 1);
(((o2 != null) && o2.method2) || $mm('method1'))(o2, 2);
(((o3 != null) && o3.method3) || $mm('method1'))(o3, 3);
(((o4 != null) && o4.method4) || $mm('method1'))(o4, 4);
(((o5 != null) && o5.method5) || $mm('method1'))(o5, 5);

(((o1 != null) && o1.method1) || $mm('method1'))(o1, 1);
(((o2 != null) && o2.method2) || $mm('method1'))(o2, 2);
(((o3 != null) && o3.method3) || $mm('method1'))(o3, 3);
(((o4 != null) && o4.method4) || $mm('method1'))(o4, 4);
(((o5 != null) && o5.method5) || $mm('method1'))(o5, 5);
pending…
(null || $mm)(mid)
(((o1 != null) && o1.method1) || $mm)(o1, 'method1', 1);
(((o2 != null) && o2.method2) || $mm)(o2,  'method1',2);
(((o3 != null) && o3.method3) || $mm)(o3, 'method1', 3);
(((o4 != null) && o4.method4) || $mm)(o4, 'method1', 4);
(((o5 != null) && o5.method5) || $mm)(o5, 'method1', 5);

(((o1 != null) && o1.method1) || $mm)(o1, 'method1', 1);
(((o2 != null) && o2.method2) || $mm)(o2, 'method1', 2);
(((o3 != null) && o3.method3) || $mm)(o3, 'method1', 3);
(((o4 != null) && o4.method4) || $mm)(o4, 'method1', 4);
(((o5 != null) && o5.method5) || $mm)(o5, 'method1', 5);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment