Created
April 30, 2010 20:26
-
-
Save lpsantil/385704 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var times = 500000 | |
function bm(label, fn) { | |
var start = +new Date | |
fn() | |
print(' ' + label + ' : ' + (+new Date - start) + ' ms') | |
} | |
print('\n running ' + times + ' times\n') | |
bm('prototype', function(){ | |
var n = times | |
while (n--) { | |
function User(name) { | |
this.name = name | |
} | |
function Admin(name) { | |
User.call(this, name) | |
} | |
new Admin('tj') | |
} | |
}) | |
bm('Object._extends_() 1', function(){ | |
var n = times | |
while (n--) { | |
function User(name) { | |
this.name = name | |
} | |
Object._extends_( Admin, User ); | |
function Admin(name) { | |
User.call(this, name) | |
} | |
new Admin('tj') | |
} | |
}) | |
bm('Object._extends_() 2', function(){ | |
var n = times | |
while (n--) { | |
function User(name) { | |
this.name = name | |
} | |
Object._extends_( Admin, User ); | |
function Admin(name) { | |
this.name = name | |
} | |
new Admin('tj') | |
} | |
}) | |
// --- Instance Creation | |
print('\n instance creation \n') | |
bm('prototype instance', function(){ | |
var n = times | |
function User(name) { | |
this.name = name | |
} | |
function Admin(name) { | |
User.call(this, name) | |
} | |
while (n--) new Admin('tj') | |
}) | |
bm('Object._extends_() 1', function(){ | |
var n = times | |
function User(name) { | |
this.name = name | |
} | |
Object._extends_( Admin, User ); | |
function Admin(name) { | |
User.call(this, name) | |
} | |
while (n--) { | |
new Admin('tj') | |
} | |
}) | |
var o; | |
bm('Object._extends_() 2', function(){ | |
var n = times | |
function User(name) { | |
this.name = name | |
} | |
Object._extends_( Admin, User ); | |
function Admin(name) { | |
this.name = name | |
} | |
while (n--) { | |
new Admin('tj') | |
} | |
o = new Admin('tj'); | |
}) | |
print( print_r( o ) ); | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment