I thought I would chime in with some memory tests. I modified
Nathan's code slightly and ran the benchmarks in Google Chrome using
Chrome's task manager to measure the memory increase for each
benchmark. Each benchmark was run in a fresh tab.
== 500,000 iterations, run 1
dynamic: 7,796K to 66,144K, 315 ms
prototype: 7,760K to 44,484K, 110 ms
dynamic 10: 7,796K to 364,440K, 1993 ms
prototype 10 methods (obj): 5,488K to 38,616K, 107 ms
prototype 10 methods (items): 7,404K to 39,952K, 109 ms
prototype 10 methods (items alt): 7,532K to 41,776K, 109 ms
== 500,000 iterations, run 2
dynamic: 5,860K to 62,948K, 256 ms
prototype: 7,792K to 44,480K, 134 ms
dynamic 10: 7,636K to 357,512K, 1986 ms
prototype 10 methods (obj): 7,796K to 40,824K, 104 ms
prototype 10 methods (items): 7,760K to 40,644K, 103 ms
prototype 10 methods (items alt): 7,556K to 40,648K, 104 ms
It looks like the average memory footprint of 500,000 objects using
the prototype patterns is 33,154K and with the dynamic method it is
353,260K.
slightly modified benchmark code:
http://gist.github.com/398273
On May 10, 8:08 pm, Scott González <
scott.gonza...@gmail.com> wrote:
> Those numbers seem much more reasonable :-)
>
>
>
>
>
> On Mon, May 10, 2010 at 11:04 PM, nwhite <
changereal...@gmail.com> wrote:
>
> > 2010/5/10 Scott González <
scott.gonza...@gmail.com>
>
> > You shouldn't be generating your constructors inside the loops. That's
> >> extra overhead that wouldn't be encountered in a real scenario.
>
> > :/ your right.
>
> > dynamic : 20 ms
> > prototype : 12 ms
> > dynamic 10 : 70 ms
> > prototype 10 methods (obj) : 10 ms
> > prototype 10 methods (items) : 11 ms
> > prototype 10 methods (items alt) : 10 ms
>
> >
http://gist.github.com/396836updated
>
> >> On Mon, May 10, 2010 at 10:22 PM, nwhite <
changereal...@gmail.com> wrote:
>
> >>> I ran some benchmarks on my laptop, each test was looped 500,000 times.
>
> >>> dynamic : 19 ms
> >>> prototype : 20 ms
> >>> dynamic 10 : 71 ms
> >>> prototype 10 methods (obj) : 945 ms
> >>> prototype 10 methods (items) : 872 ms
> >>> prototype 10 methods (items alt) : 846 ms
>
> >>> benchmark code :
http://gist.github.com/396836
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "nodejs" group.
> >>> To post to this group, send email to
nod...@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>>
nodejs+un...@googlegroups.com<
nodejs%2Bunsu...@googlegroups.com>
> >>> .
> >>
nodejs+un...@googlegroups.com<
nodejs%2Bunsu...@googlegroups.com>
> >> .
> >
nodejs+un...@googlegroups.com<
nodejs%2Bunsu...@googlegroups.com>
> > .
> For more options, visit this group athttp://
groups.google.com/group/nodejs?hl=en.