Sunday, November 20, 2016

Prototype Pattern vs. Revealing Prototype Pattern Memory Benchmark

Last week I benchmarked the Prototype Pattern and the Module Pattern in this post. This week I will add the Revealing Prototype Pattern to the list of benchmarks.

The Revealing Prototype Pattern is a hybrid of the Prototype Pattern and the Module Pattern. It is supposed to be the best of both worlds. The module will have private variables and functions and will only expose a public API while still conserving memory.

As you will see the memory used is very close to the Prototype Pattern. If the style of code you write uses the Prototype Pattern then switching to the Revealing Prototype Pattern will give you the benefits of private variables and functions with minimal memory cost.

Listed below are the benchmarks and code.

Table of Results:
Objects Created
Prototype Pattern
Memory (MB)
Module Pattern
Memory (MB)
Revealing Prototype Pattern
Memory (MB)
1
0.001832
0.002624
0.001832
5
0.003224
0.004232
0.003296
10
0.003552
0.005552
0.003624
100
0.009320   
0.031480
0.009392
1000
0.079240
0.294816
0.079400
10000
0.298288
2.378696
0.298544


No comments:

Post a Comment