isCompatProxy Speed

JavaScript performance comparison

Test case created by tariq-sfdc

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var ProxySlotDynamic = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = Math.random() * 16 | 0,
        v = c === 'x' ? r : r & 0x3 | 0x8;
    return v.toString(16);
  });
  
  var ProxyIdentifier = function ProxyCompat() {};
  
  var obj = {x: 1, get: function() { return 1;} };
  var objNoProxy = {x:1};
  
  obj[ProxySlotDynamic] = ProxyIdentifier;
  obj.__ProxySlotStatic__ = ProxyIdentifier
  
  function isCompatProxy(replicaOrAny) {
    return replicaOrAny && replicaOrAny[ProxySlotDynamic] === ProxyIdentifier;
  }
  
  function isCompatProxyHasOwnProperty(replicaOrAny) {
    return replicaOrAny && hasOwnProperty.call(replicaOrAny, ProxySlotDynamic);
  }
  
  function isCompatProxyStatic(replicaOrAny) {
    return replicaOrAny && replicaOrAny.__ProxySlotStatic__ === ProxyIdentifier;
  }
  
  
  var getKey = function (replicaOrAny, k1) {
    return isCompatProxy(replicaOrAny) ? replicaOrAny.get(k1) : replicaOrAny[k1];
  };
  
  var getKeyHasOwnProperty = function (replicaOrAny, k1) {
    return isCompatProxyHasOwnProperty(replicaOrAny) ? replicaOrAny.get(k1) : replicaOrAny[k1];
  };
  
  var getKeyStaticProxy = function (replicaOrAny, k1) {
    return replicaOrAny && replicaOrAny.__ProxySlotStatic__ === ProxyIdentifier ? replicaOrAny.get(k1) : replicaOrAny[k1];
  };
  
  var getKeyStaticProxyNoInline = function (replicaOrAny, k1) {
    return isCompatProxyStatic(replicaOrAny) ? replicaOrAny.get(k1) : replicaOrAny[k1];
  };

};
</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
getKey dynamic proxy slot
var t = getKey(obj, 'x');
t = t + 1;
pending…
getKey static proxy slot
var t = getKeyStaticProxy(obj, 'x');
t = t + 1;
pending…
getKey static proxy slot noinline
var t = getKeyStaticProxyNoInline(obj, 'x');
t = t + 1;
pending…
getKey hasOwnProperty dynamic proxy slot
var t = getKeyHasOwnProperty(obj, 'x');
t = t + 1;
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