redefine-js

JavaScript performance comparison

Test case created by WebReflection

Info

some test showing that redefine is smarter than manual operations with ES5 problems.

Preparation code

<script>

function descriptor(object) {
  // now don't take this wrong
  // but this function is almost
  // as big as the whole redefine.js library
  // I would not go through this pattern
  for (var
    nullDescriptor = Object.create(null),
    properties = [
      "configurable",
      "enumerable",
      "writable",
      "get",
      "set",
      "value"
    ],
    i = properties.length; i--;
    object.hasOwnProperty(properties[i]) && (
      nullDescriptor[properties[i]] = object[properties[i]]
    )
  );
  return nullDescriptor;
}


// setting up the nasty environment
Object.prototype.configurable =
Object.prototype.enumerable =
Object.prototype.writable = true;



// redefine v0.1.1
/*! (C) WebReflection *//** @preserve https://github.com/WebReflection/redefine */
var _=this._=function(e,m,d){function n(a,r,c,d){if(!(c instanceof v))if(c instanceof w){var e=c._,h=f.call(c,p)?!!c[p]:!0,m=f.call(c,q)&&c[q],n=f.call(c,k)&&c[k],s;c[t]=function(){b[j]=e.call(s=this);b[p]=h;b[q]=m;b[k]=n;x(s,r,b);y(b);return s[r]}}else c=(u[j]=c,u);l(d||g.defaults||{},b);l(c,b);if(f.call(c,t)||f.call(c,z))delete b[k],delete b[j];x(a,r,b);y(b);delete u[j]}function v(a){l(a,this)}function w(a){this._="function"==typeof a?a:l(a,this)||a[j]}function g(a,b,c,d){if("string"==typeof b)n(a,
b,c,d);else for(var e in b)f.call(b,e)&&n(a,e,b[e],c);return a}var p="configurable",q="enumerable",t="get",z="set",j="value",k="writable",x=e.defineProperty||d.defineProperty,f=e.hasOwnProperty||d.hasOwnProperty,A=e.create||e.inherit||d.create;d=[p,q,t,z,j,k];var y=m("o","delete o."+d.join(";delete o.")),b=A(null),u={},h,l;for(h=0;h<d.length;h++)d[h]=["if(h.call(a,'","'))b.","=a.",";"].join(d[h]);l=m("h","return function(a,b){"+d.join("")+"}")(f);g.as=function(a){return new v(a)};g.from=function(a,
b,c){a=A("function"==typeof a?a.prototype:a);return b?g(a,b,c):a};g.later=function(a){return new w(a)};g.defaults={};e.redefine=g;return e}(_||this,Function,Object);
</script>
<script>
Benchmark.prototype.setup = function() {
    var result;
};
</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
redefine.js
result = redefine({}, "problem", "solved");
pending…
Object.defineProperty
result = Object.defineProperty({}, "problem", descriptor({value: "solved"}));
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