
JavaScript Classes vs. Closures – Performance - twitchard
https://medium.com/engineering-livestream/javascript-classes-v-closures-2-3-9fa3b1296b16
======
atomopawn
So I ran your two programs through SpiderNode just to see how they perform
with SpiderMonkey as the engine instead of V8. As expected, the average time
is a little higher, but that is especially true of the closure implementation.
Running ten trials of both programs and taking the averages, I find that the
class implementation takes about 11.65 seconds with an average resident set
size of 40,099,430.4 bytes, a heap total of 9,437,184 bytes, a heap used of
6,022,144 bytes. The closure implementation takes 12.76 seconds with rss of
55,508,172.8 bytes, heap total of 16,777,216 bytes, and a heap used
of12,836,696 bytes.

In other words, the time and memory differences are much smaller (both are
inefficient when using SpiderNode), but the closure technique actually takes
longer than the class implementation.

------
atomopawn
Good analysis. Interestingly, when I try to duplicate your results, the class
implementation takes twice as long as the closure implementation (10 seconds
vs 5). I'm using v4.2.6 of node, though. Clearly v6 makes a big difference.

