ternary-vs-explicit

Benchmark created by clux on


Preparation HTML

<script>
  Number.prototype.pluralizeCoffee = function(singular, plural) {
    if (plural == undefined) {
      plural = singular + 's';
    }
    if (this === 1) {
      return this + ' ' + singular;
    } else {
      return this + ' ' + plural;
    }
  };
  
  Number.prototype.pluralize = function(singular, plural){
    if (plural == undefined) plural = singular + 's';
    return this + ' ' + (this == 1 ? singular : plural);
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
coffee input
(5).pluralizeCoffee('unit');
(3).pluralizeCoffee('entry', 'entries');
(1).pluralizeCoffee('entry', 'entries');
ready
plain js
(5).pluralize('unit');
(3).pluralize('entry', 'entries');
(1).pluralize('entry', 'entries');
ready

Revisions

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