BabelJS vs CoffeeScript Super Calls

Benchmark created by Jeremy Ashkenas on


Setup

"use strict";
    
    var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
    
    var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
    
    var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
    
    var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
    
    var BabelA = (function () {
      function BabelA() {
        _classCallCheck(this, BabelA);
      }
    
      _prototypeProperties(BabelA, null, {
        update: {
          value: function update(val) {
            return val + 1;
          },
          writable: true,
          configurable: true
        }
      });
    
      return BabelA;
    })();
    
    var BabelB = (function (BabelA) {
      function BabelB() {
        _classCallCheck(this, BabelB);
    
        if (BabelA != null) {
          BabelA.apply(this, arguments);
        }
      }
    
      _inherits(BabelB, BabelA);
    
      _prototypeProperties(BabelB, null, {
        update: {
          value: function update(val) {
            return _get(Object.getPrototypeOf(BabelB.prototype), "update", this).call(this, val);
          },
          writable: true,
          configurable: true
        }
      });
    
      return BabelB;
    })(BabelA);
    
    var CoffeeA, CoffeeB,
      extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
      hasProp = {}.hasOwnProperty;
    
    CoffeeA = (function() {
      function CoffeeA() {}
    
      CoffeeA.prototype.update = function(val) {
        return val + 1;
      };
    
      return CoffeeA;
    
    })();
    
    CoffeeB = (function(superClass) {
      extend(CoffeeB, superClass);
    
      function CoffeeB() {
        return CoffeeB.__super__.constructor.apply(this, arguments);
      }
    
      CoffeeB.prototype.update = function(val) {
        return CoffeeB.__super__.update.call(this, val);
      };
    
      return CoffeeB;
    
    })(CoffeeA);
    
    babelInstance = new BabelB;
    coffeeInstance = new CoffeeB;
    
    var mediumArray = [];
    for (var i = 0; i < 10000; i++) {
      mediumArray[i] = i;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
CoffeeScript Super
coffeeInstance.update(100)
ready
BabelJS Super
babelInstance.update(100)
ready

Revisions

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

  • Revision 1: published by Jeremy Ashkenas on