<script src="https://pkgzip.com/bundle.js?packages=memoize-one@4.0.1,fast-memoize@2.2.0,underscore@1.8.3,lodash@4.17.4,moize@2.2.1,memoizejs@0.1.1,moize@2.2.1,reselect@2.5.4"></script>
var fn = function() {
for(var i = 0; i < 2000; i++) {
void(undefined);
}
}
var modules = window.pkgzip;
var memoizeOneFn = modules.memoizeOne.default(fn);
var fastMemoizeFn = modules.fastMemoize(fn);
var underscoreFn = modules.underscore.memoize(fn);
var lodashFn = modules.lodash.memoize(fn);
var memoizejsFn = modules.memoizejs(fn);
var reselectFn = modules.reselect.defaultMemoize(fn);
var moizeFn = modules.moize(fn);
fn(1, 2);
memoizeOneFn(1, 2);
fastMemoizeFn(1, 2);
lodashFn(1, 2);
underscoreFn(1, 2);
memoizejsFn(1, 2);
reselectFn(1, 2);
moizeFn(1, 2)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
baseline | |
memoizeOne | |
fastMemoize | |
lodash | |
underscore | |
memoizejs | |
reselect | |
moize |
Test name | Executions per second |
---|---|
baseline | 2999.7 Ops/sec |
memoizeOne | 5526027.5 Ops/sec |
fastMemoize | 1207962.6 Ops/sec |
lodash | 4934974.5 Ops/sec |
underscore | 5570480.5 Ops/sec |
memoizejs | 1102784.5 Ops/sec |
reselect | 4673592.0 Ops/sec |
moize | 4714124.0 Ops/sec |
Let's break down the benchmark and explain what is being tested.
Benchmark Description
The benchmark is comparing the performance of different memoization libraries in JavaScript: memoizeOne
, fastMemoize
, underscore.memoize
, lodash.memoize
, moize
, and reselect.defaultMemoize
. Memoization is a technique used to optimize performance by caching the results of expensive function calls.
Options Compared
The benchmark compares the performance of each library in different scenarios:
fastMemoize
library, which is expected to be faster than the others.reselect
, a library primarily designed for data fetching and caching, but also includes a memoization mechanism.Pros and Cons of Each Approach
Here's a brief summary of the pros and cons of each approach:
fastMemoize
.Library Descriptions
memoize
function from the Underscore.js library, providing a convenient way to cache function results.memoize
function from the Lodash library, offering more features and flexibility than the standalone version.Benchmark Results
The benchmark results show that:
fastMemoize
is significantly faster than the other libraries in most tests.reselect.defaultMemoize
performs well in specific use cases but has slower overall performance.memoizeOne
, lodash.memoize
, and moize
are competitive with each other, offering good performance and flexibility.Keep in mind that these results may vary depending on the specific use case and requirements of your application.