asset type

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    //by function
    function assertType(obj, type) {
        return obj.constructor.name === type.name
    }
    //prototype
    Object.prototype.assertType = function(type) {
        return this.constructor.name === type.name
    }
   
    //mock objects
    function Book(){};
    function Desk(){};
    var book = new Book();
    var one = 1;
   
   
};
</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
function
assertType("test", String); //true
assertType(one, String); //false
assertType(one, Number); //true
assertType(book, Book); //true
assertType(book, Desk); //false
 
assertType([], Array); //true
assertType(function(){}, Function); //true
 
pending…
prototype
"test".assertType(String); //true
one.assertType(String); //false
one.assertType(Number); //true
book.assertType(Book); //true
book.assertType(Desk); //false
 
[].assertType(Array); //true
(function(){}).assertType(Function); //true
 
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