Created
April 30, 2014 11:15
-
-
Save bichotll/c6701673764950e558f5 to your computer and use it in GitHub Desktop.
javascript private methods benchmark
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
/* | |
The aim of this test is to check the performance (as speed) and the memory creating instances of objects with public or private methods. | |
We want to see if create a private method in js really hurts the performance. | |
For that we will compare the performance creating so many instances and checking the performance | |
*/ | |
function Public(){ | |
this.publicMethod = function(){ | |
}; | |
} | |
function Private(){ | |
var privateMethod = function(){ | |
} | |
} | |
console.time("Private method"); | |
var array = new Array(1000000); | |
for (var i = array.length - 1; i >= 0; i--) { | |
array[i] = new Private(); | |
}; | |
console.timeEnd("Private method"); | |
console.time("Public method"); | |
var array = new Array(1000000); | |
for (var i = array.length - 1; i >= 0; i--) { | |
array[i] = new Public(); | |
}; | |
console.timeEnd("Public method"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment