Default Parameter Value: ECMAScript 6 vs CoffeeScript

Benchmark created by KenOfYugen on


Description

Evaluation of Default Parameter Values in ES5, ES6 and CoffeeScript generated code.

CoffeeScript code used:

--------CodeStart-------

inc = (x, y = 1) -> x + y

inc 4

---------CodeEnd--------

Test runner

Ready to run.

Testing in
TestOps/sec
ES5 Hackish Workaround
function inc(x, y) {
  y = y || 1;
  return x + y;
}

inc(4);
ready
ES6 default parameter value
function inc(x, y = 1) { return x += y; };

inc(4);
ready
Generated CoffeeScript default values for arguments
// Generated by CoffeeScript 1.7.1
(function() {
  var inc;

  inc = function(x, y) {
    if (y == null) {
      y = 1;
    }
    return x + y;
  };

  inc(4);

}).call(this);
 
ready

Revisions

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

  • Revision 1: published by KenOfYugen on