Serialize tree

JavaScript performance comparison

Test case created by metalim

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  Data = ['1234567890', '2234567890', '3234567890', '4234567890']
  function _val(lvl, id) { return Data[lvl*id % Data.length] }
  
  Depth = 8
  Spread = 4
  
  function tree(lvl = 0, id = 0) {
    let out = _val(lvl,id)
    if (lvl < Depth) {
      for (let i = 0; i < Spread; ++i) {
        out += tree(lvl + 1, id + i)
      }
    }
    return out
  }
  
  function pass_string(lvl = 0, id = 0, out = '') {
    out += _val(lvl, id)
    if (lvl < Depth) {
      for (let i = 0; i < Spread; ++i) {
        out = pass_string(lvl + 1, id + i, out)
      }
    }
    return out
  }
  
  function pass_obj(lvl = 0, id = 0, out = {txt: ''}) {
    out.txt += _val(lvl, id)
    if (lvl < Depth) {
      for (let i = 0; i < Spread; ++i) {
        pass_obj(lvl + 1, id + i, out)
      }
    }
    return out
  }
  
  function enclose() {
    let out = ''
    function _encl(lvl, id) {
      out += _val(lvl, id)
      if (lvl < Depth) {
        for (let i = 0; i < Spread; ++i) {
          _encl(lvl + 1, id + i)
        }
      }
    }
    _encl(0, 0)
    return out
  }

};
</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
1. Straight forward (tree of strings)
tree()
pending…
2. Pass buffer string as argument
pass_string()
pending…
3. Pass object as argument
pass_obj()
pending…
4. Use enclosure
enclose()
pending…

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

Compare results of other browsers

0 Comments