prototype - Does JavaScript Object initialization time depends on number of Variables and function? -
ques 1: take more time initialize javascript object if has large number of variables , functions?
ques 2: large javascript(.js) file size performance issue?
for instance: creating javascript object using prototype, sample code below:
function simpleobject(){ // no variables , functions attached } function rootobject(){ var 1 = "one"; var 2 = "two"; . . var one_thousand = "one thousand"; } function child_1_object(){ // n number of variables } . . function child_1000_object(){ // n number of variables } rootobject.prototype.get_child_1_object = function(){ return new child_1_object(); } . . rootobject.prototype.get_child_1000_object = function(){ return new child_1000_object(); }
all above code in 1 .js file has 10k lines of code(10kloc).
question when create object of rootobject
take more time comparing creation of simpleobject
?
question one:
making object more complicated, members, functions etc. increase amount of time needed instantiate it. wrote simple jsperf test here prove point: http://jsperf.com/simple-vs-complex-object
one thing note though, you're still creating hundreds of thousands of objects second - it's hardly slow, complex objects.
question two:
large files problematic because of size in terms of client having download them. minifying code this. e.g. http://javascript-minifier.com/
Comments
Post a Comment