Created
January 4, 2018 14:04
-
-
Save davedx/9a4003e589e6e80a0947c6d4896b7c00 to your computer and use it in GitHub Desktop.
getter_perf
This file contains 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 A = { | |
_propA: 'fish', | |
_propB: `cat${this._propA}` | |
} | |
var B = { | |
_propA: 'fish', | |
_propB: 'cat', | |
get propA() { | |
return this._propA | |
}, | |
get propB() { | |
return this._propB + this._propA | |
} | |
} | |
var C = { | |
_propA: 'fish', | |
_propB: 'cat', | |
propA: function () { | |
return this._propA | |
}, | |
propB: function () { | |
return this._propB + this._propA | |
} | |
} | |
var R, S; | |
var its = 10000000 | |
T = Date.now() | |
for (var i=0; i<its; i++) { | |
R = A._propA; | |
S = A._propB; | |
} | |
console.log(`Elapsed: ${Date.now()-T}`) | |
T = Date.now() | |
for (var i=0; i<its; i++) { | |
R = B.propA; | |
S = B.propB; | |
} | |
console.log(`Elapsed: ${Date.now()-T}`) | |
T = Date.now() | |
for (var i=0; i<its; i++) { | |
R = C.propA(); | |
S = C.propB(); | |
} | |
console.log(`Elapsed: ${Date.now()-T}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Daves-MacBook-Pro:~ dave$ node -v
v6.9.2
Daves-MacBook-Pro:~ dave$ node getter_perf.js
Elapsed: 96
Elapsed: 2237
Elapsed: 186