Accessing prototyped and static objects

JavaScript performance comparison

Test case created by Pijus Navickas

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function A(name) {
        this.getName = function() {
            return name
        }
        this.getSmile = function() {
            return  ':)'
        }
    }
   
    function B(name) {
        this._name = name
    }
   
    B.prototype.getName = function() {
        return this._name
    }
   
    B.prototype.getSmile = function() {
        return ':)'
    }
   
    var a = new A('cool')
    var b = new B('cool')
};

Benchmark.prototype.teardown = function() {
    delete A
    delete B
    delete a
    delete b
};
</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
Static with variables
a.getName()
pending…
Static without variables
a.getSmile()
pending…
Prototyped with variables
b.getName()
pending…
Prototyped without variables
b.getSmile()
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