I have been tying to profile the class creation of PrototypeJS and Next!. Unfortanly i was not able to find a fair result, because i evaluated full prototype since everything depends on everything :S
I would be a hard trick to remove all uneed stuff.
So i tested by doing this( this is not real code, just graph )
Class Animal
name
constructor(name)
this.name=name;
say(message)
alert(this.name + ": " + message);
eat(food)
this.say("Yum!");
Class Cat extends Animal
constructor()
super("cat");
eat(food)
if (food instanceof Mouse)
super.eat();
else if (food instanceof BadMouse)
this.say("i dont like bad mouse");
else
this.say("Whatever you gaved me to eat, i dont like");
Class Lion extends Cat
constructor()
super("lion");
say(message)
super.say(message.toUpperCase());//big
Class Mouse extends Animal
constructor()
super("mouse")
Class BadMouse extends Mouse
var l= new Lion();
I picked this and created class with Next! and with PrototypeJS and used Firebug to profile and see how much function calls are done and how much time it taken
Next! ( Just class stuff ): Profile (0ms, 11 calls)
Prototype (full): Profile (31.25ms, 1091 calls)
Theres a Huge diference, but we must dont forget that most of this calls are from PrototypeJS base, its impossible to make a good comparission
But one thing i can say none of those 11 calls are iterating over objects to extend
In the end, PrototypeJS code looks a bit better and might be some char's smaller but overuses object extending stuf, and its slower to parse
No comments:
Post a Comment