ltree-test-3

JavaScript performance comparison

Test case created by

Preparation code

<script>
Benchmark.prototype.setup = function() {
  
function twice(fn) {
  fn();
  fn();
  fn();
  fn();
}

function putArray(line) {
  var values = [];
  twice( () => {
    const chunks = line.split('.');
    var len = chunks.length - 1; // remove "last part"
    var value = chunks[0];
    if (values.indexOf(value) < 0) values.push(value);
    for (var i = 1; i < len; i++) {
      value = value + '.' + chunks[i];
      if (values.indexOf(value) < 0) values.push(value);
    }
  });
  return values;
}

function putArray2(line) {
  var values = [];
  twice( () => {
    var index = line.lastIndexOf('.');
    if (index < 0) {
      if (values.indexOf(line) < 0) values.push(line);
    } else {
      while (index >= 0) {
        var value = line.slice(0, index);
        if (values.indexOf(value) < 0) values.push(value);
        index = line.lastIndexOf('.', index - 1);
      }
    }
  });
  return values;
}

function putArray3(lineOrig) {
  var values = [];
  twice( () => {
    var line = lineOrig;
    var index = line.lastIndexOf('.');
    if (index < 0) {
      if (values.indexOf(line) < 0) values.push(line);
    } else {
      while (index >= 0) {
        line = line.slice(0, index);
        if (values.indexOf(line) < 0) values.push(line);
        index = line.lastIndexOf('.');
      }
    }
  });
  return values;
}

function putArray4(lineOrig) {
  var values = [];
  twice( () => {
    var line = lineOrig;
    var index = line.lastIndexOf('.');
    if (index < 0) {
      if (values.indexOf(line) < 0) values.push(line);
    } else {
      while (index >= 0) {
        line = line.slice(0, index);
        if (values.indexOf(line) < 0) {
          values.push(line);
          index = line.lastIndexOf('.');
        } else {
          break; // done that
        }
      }
    }
  });
  return values;
}

function putArray5(line) {
  var values = [];
  twice( () => {
    var index = line.lastIndexOf('.');
    if (index < 0) {
      if (values.indexOf(line) < 0) values.push(line);
    } else {
      while (index >= 0) {
        var value = line.slice(0, index);
        if (values.indexOf(value) < 0) {
          values.push(value);
          index = line.lastIndexOf('.', index - 1);
        } else {
          break; // done that
        }
      }
    }
  });
  return values;
}

};
</script>

    

Preparation code output

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
array-short
putArray('test.test');
pending…
array2-short
putArray2('test.test');
pending…
array3-short
putArray3('test.test');
pending…
array-long
putArray('test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test');
pending…
array2-long
putArray2('test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test');
pending…
array3-long
putArray3('test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test');
pending…
array4-short
putArray4('test.test');
pending…
array4-long
putArray4('test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test');
pending…
array5-short
putArray5('test.test');
pending…
array5-long
putArray5('test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test.test');
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