ltree-test-2

JavaScript performance comparison

Test case created by dai-shi

Preparation code

<script>
Benchmark.prototype.setup = function() {
  
  function putSet(line) {
    const values = new Set();
    const chunks = line.split('.');
    chunks.pop(); // remove "last part"
    chunks.reduce((acc, name) => {
      if (acc) {
        acc = acc + '.' + name;
      } else {
        acc = name;
      }
      values.add(acc);
      return acc;
    }, '');
    return values;
  }

  function putSet2(line) {
    const values = new Set();
    const chunks = line.split('.');
    var len = chunks.length - 1; // remove "last part"
    var value = chunks[0];
    values.add(value);
    for (var i = 1; i < len; i++) {
      value = value + '.' + chunks[i];
      values.add(value);
    }
    return values;
  }

  function putArray(line) {
    const chunks = line.split('.');
    var len = chunks.length - 1; // remove "last part"
    var value = chunks[0];
    var values = [value];
    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;
  }

};
</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
set-long
putSet('test.test.test.test.test.test');
pending…
set-long-2
putSet2('test.test.test.test.test.test');
pending…
array-long
putArray('test.test.test.test.test.test');
pending…
set-short
putSet('test.test');
pending…
set-short-2
putSet2('test.test');
pending…
array-short
putArray('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