field-query

JavaScript performance comparison

Test case created by Irakli Gozilishvili

Info

Attempt to benchmark object property lookup functions

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function query(path) {
      return function(target) {
        var names = path.split(".")
        var count = names.length
        var index = 0
        var result = target
        while (result && index < count) {
          result = result[names[index]]
          index = index + 1
        }
        return result
      }
    }
   
    function query2(path) {
      return new Function("$", "return $." + path)
    }
   
    var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map(function(x) {
      return { target: { parent: { id: x } } }
    })
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
high-order
var id = query("target.parent.id")
var ids = data.map(id)
 
pending…
generated
var id = query2("target.parent.id")
var ids = data.map(id)
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

Add a comment