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…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment