ES6 isClass

JavaScript performance comparison

Test case created by Shane Brinkman-Davis

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  class MyClass {foo(){}}
  isClassRegExp = /^\s*class\s+/
  
  // This is generally effective, but not strictly correct -
  // A class can have a prototype with no keys.
  function prototypeHasKeys(fn) {
    if (!fn) {return false;}
    var obj = fn.prototype;
    var k;
    for (k in obj) {
      return true;
    }
    return false;
  };

};
</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
isClassRegExp.test(MyClass.toString())
isClassRegExp.test(MyClass.toString())
pending…
typeof - if it returned "class"
typeof MyClass == "function"
pending…
prototypeHasKeys(MyClass)
prototypeHasKeys(MyClass)
pending…

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

0 Comments