template tag to string

JavaScript performance comparison

Test case created by WebReflection

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var result = '';
  
  function bothLength(template) {
    let target = '';
    for (let
      i = 0,
      t = template.length,
      a = arguments.length;
      i < a && i < t;
      i++
    )
      target += (i ? arguments[i] : '') + template[i];
    return target;
  }
  
  function pushLength(template) {
    let target = template.slice(0, 1);
    for (let
      i = 1,
      t = template.length,
      a = arguments.length;
      i < a && i < t;
      i++
    )
      target.push(arguments[i], template[i]);
    return target.join('');
  }
  
  function templateLength(template) {
    let target = template[0];
    for (let i = 1, t = template.length; i < t; i++)
      target += arguments[i] + template[i];
    return target;
  }
  
  function argumentsLength(template) {
    let target = template[0];
    for (let i = 1, a = arguments.length; i < a; i++)
      target += arguments[i] + template[i];
    return target;
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
bothLength
result = bothLength`a${Math.random()}b${Math.random()}c`;
pending…
pushLength
result = pushLength`a${Math.random()}b${Math.random()}c`;
pending…
templateLength
result = templateLength`a${Math.random()}b${Math.random()}c`;
pending…
argumentsLength
result = argumentsLength`a${Math.random()}b${Math.random()}c`;
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.

0 Comments