Alias lookups in TypedArrays

Benchmark created by Steve Kane on


Description

Here we compare a lookup by index into a typed array versus defining an alias to that element using Object.defineProperty

Setup

var Mat1 = function (x) {
      var out = new Float32Array(1)
    
      out[0] = x
    
      Object.defineProperty(out, "x", {
        get: function () { return out[0] },
        set: function (v) { out[0] = v }
      })
    
      return out
    }
    
    var m = Mat1(5)

Test runner

Ready to run.

Testing in
TestOps/sec
Lookup by index
var p = m[0]
ready
Lookup by alias
var l = m.x
ready

Revisions

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

  • Revision 1: published by Steve Kane on