nano-memoize
Advanced tools
Comparing version 3.0.8 to 3.0.9
@@ -54,3 +54,2 @@ 'use strict'; | ||
const fastDeepEqual = require('fast-deep-equal/ES6'); | ||
const hashItEquals = require('hash-it').isEqual; | ||
@@ -138,3 +137,3 @@ const showResults = (benchmarkResults) => { | ||
const fibonacciMultipleObject = (number, check) => { | ||
const fibonacciMultipleMixed = (number, check) => { | ||
if (check.isComplete) { | ||
@@ -148,6 +147,6 @@ return number; | ||
return ( | ||
fibonacciMultipleObject(firstValue, { | ||
fibonacciMultipleMixed(firstValue, { | ||
isComplete: firstValue < 2 | ||
}) + | ||
fibonacciMultipleObject(secondValue, { | ||
fibonacciMultipleMixed(secondValue, { | ||
isComplete: secondValue < 2 | ||
@@ -158,10 +157,28 @@ }) | ||
const fibonacciMultipleDeepEqual = ({number}) => { | ||
const fibonacciSingleObject = ({number}) => { | ||
return number < 2 | ||
? number | ||
: fibonacciMultipleDeepEqual({number: number - 1}) + fibonacciMultipleDeepEqual({number: number - 2}); | ||
: fibonacciSingleObject({number: number - 1}) + fibonacciSingleObject({number: number - 2}); | ||
}; | ||
const fibonacciMultipleObject = ({number}, check) => { | ||
if (check.isComplete) { | ||
return number; | ||
} | ||
const firstValue = number - 1; | ||
const secondValue = number - 2; | ||
return ( | ||
fibonacciMultipleObject({number:firstValue}, { | ||
isComplete: firstValue < 2 | ||
}) + | ||
fibonacciMultipleObject({number:secondValue}, { | ||
isComplete: secondValue < 2 | ||
}) | ||
); | ||
}; | ||
const runSingleParameterSuite = () => { | ||
const fibonacciSuite = new Benchmark.Suite('Single parameter'); | ||
const fibonacciSuite = new Benchmark.Suite('Single primitive parameter'); | ||
const fibonacciNumber = 35; | ||
@@ -241,17 +258,17 @@ | ||
const runSingleParameterObjectSuite = () => { | ||
const fibonacciSuite = new Benchmark.Suite('Single parameter'); | ||
const fibonacciNumber = Number(35); | ||
const fibonacciSuite = new Benchmark.Suite('Single object parameter'); | ||
const fibonacciNumber = {number:35}; | ||
const mUnderscore = underscore(fibonacci); | ||
const mLodash = lodash(fibonacci); | ||
// const mRamda = ramda(fibonacci); | ||
const mMemoizee = memoizee(fibonacci); | ||
const mFastMemoize = fastMemoize(fibonacci); | ||
const mAddyOsmani = addyOsmani(fibonacci); | ||
const mMemoizerific = memoizerific(Infinity)(fibonacci); | ||
const mLruMemoize = lruMemoize(Infinity)(fibonacci); | ||
const mMoize = moize(fibonacci); | ||
const mMicroMemoize = microMemoize(fibonacci); | ||
const mIMemoized = iMemoized.memoize(fibonacci); | ||
const mNano = nanomemoize(fibonacci,{relaxed:true}); | ||
const mUnderscore = underscore(fibonacciSingleObject); | ||
const mLodash = lodash(fibonacciSingleObject); | ||
// const mRamda = ramda(fibonacciSingleObject); | ||
const mMemoizee = memoizee(fibonacciSingleObject); | ||
const mFastMemoize = fastMemoize(fibonacciSingleObject); | ||
const mAddyOsmani = addyOsmani(fibonacciSingleObject); | ||
const mMemoizerific = memoizerific(Infinity)(fibonacciSingleObject); | ||
const mLruMemoize = lruMemoize(Infinity)(fibonacciSingleObject); | ||
const mMoize = moize(fibonacciSingleObject); | ||
const mMicroMemoize = microMemoize(fibonacciSingleObject); | ||
const mIMemoized = iMemoized.memoize(fibonacciSingleObject); | ||
const mNano = nanomemoize(fibonacciSingleObject); | ||
@@ -380,8 +397,9 @@ | ||
const runMultipleObjectSuite = () => { | ||
const fibonacciSuite = new Benchmark.Suite('Multiple parameters (Object)'); | ||
const fibonacciNumber = 35; | ||
const isComplete = { | ||
isComplete: false | ||
}; | ||
const fibonacciSuite = new Benchmark.Suite('Multiple object parameter'); | ||
const fibonacciNumber = {number:35}; | ||
const check = {}; | ||
const mUnderscore = underscore(fibonacciMultipleObject); | ||
const mLodash = lodash(fibonacciMultipleObject); | ||
// const mRamda = ramda(fibonacciMultipleObject); | ||
const mMemoizee = memoizee(fibonacciMultipleObject); | ||
@@ -394,3 +412,78 @@ const mFastMemoize = fastMemoize(fibonacciMultipleObject); | ||
const mMicroMemoize = microMemoize(fibonacciMultipleObject); | ||
const mIMemoized = iMemoized.memoize(fibonacciMultipleObject); | ||
const mNano = nanomemoize(fibonacciMultipleObject); | ||
return new Promise((resolve) => { | ||
fibonacciSuite | ||
.add('nano-memoize', () => { | ||
mNano(fibonacciNumber,check); | ||
}) | ||
.add('addy-osmani', () => { | ||
mAddyOsmani(fibonacciNumber,check); | ||
}) | ||
.add('lodash', () => { | ||
mLodash(fibonacciNumber,check); | ||
}) | ||
.add('lru-memoize', () => { | ||
mLruMemoize(fibonacciNumber,check); | ||
}) | ||
.add('memoizee', () => { | ||
mMemoizee(fibonacciNumber,check); | ||
}) | ||
.add('memoizerific', () => { | ||
mMemoizerific(fibonacciNumber,check); | ||
}) | ||
/*.add('ramda', () => { | ||
mRamda(fibonacciNumber); | ||
})*/ | ||
.add('underscore', () => { | ||
mUnderscore(fibonacciNumber,check); | ||
}) | ||
.add('iMemoized', () => { | ||
mIMemoized(fibonacciNumber,check); | ||
}) | ||
.add('micro-memoize', () => { | ||
mMicroMemoize(fibonacciNumber,check); | ||
}) | ||
.add('moize', () => { | ||
mMoize(fibonacciNumber,check); | ||
}) | ||
.add('fast-memoize', () => { | ||
mFastMemoize(fibonacciNumber,check); | ||
}) | ||
.on('start', () => { | ||
console.log(''); // eslint-disable-line no-console | ||
console.log('Starting cycles for functions with multiple object parameters...'); // eslint-disable-line no-console | ||
results = []; | ||
spinner.start(); | ||
}) | ||
.on('cycle', onCycle) | ||
.on('complete', () => { | ||
onComplete(); | ||
resolve(); | ||
}) | ||
.run({ | ||
async: true | ||
}); | ||
}); | ||
}; | ||
const runMultipleMixedSuite = () => { | ||
const fibonacciSuite = new Benchmark.Suite('Multiple mixed parameters'); | ||
const fibonacciNumber = 35; | ||
const isComplete = { | ||
isComplete: false | ||
}; | ||
const mMemoizee = memoizee(fibonacciMultipleMixed); | ||
const mFastMemoize = fastMemoize(fibonacciMultipleMixed); | ||
const mAddyOsmani = addyOsmani(fibonacciMultipleMixed); | ||
const mMemoizerific = memoizerific(Infinity)(fibonacciMultipleMixed); | ||
const mLruMemoize = lruMemoize(Infinity)(fibonacciMultipleMixed); | ||
const mMoize = moize(fibonacciMultipleMixed); | ||
const mMicroMemoize = microMemoize(fibonacciMultipleMixed); | ||
const mNano = nanomemoize(fibonacciMultipleMixed); | ||
@@ -425,3 +518,3 @@ return new Promise((resolve) => { | ||
console.log(''); // eslint-disable-line no-console | ||
console.log('Starting cycles for functions with multiple parameters that contain objects...'); // eslint-disable-line no-console | ||
console.log('Starting cycles for functions with multiple mixed parameters ...'); // eslint-disable-line no-console | ||
@@ -444,3 +537,3 @@ results = []; | ||
const runAlternativeOptionsSuite = () => { | ||
const fibonacciSuite = new Benchmark.Suite('Multiple parameters (Object)'); | ||
const fibonacciSuite = new Benchmark.Suite('Alternative single object'); | ||
const fibonacciNumber = { | ||
@@ -450,50 +543,76 @@ number: 35 | ||
const mMicroMemoizeDeep = microMemoize(fibonacciMultipleDeepEqual, { | ||
const mMicroMemoizeDeepEquals = microMemoize(fibonacciSingleObject, { | ||
isEqual: deepEquals | ||
}); | ||
const mMicroMemoizeFastDeep = microMemoize(fibonacciMultipleDeepEqual, { | ||
const mMicroMemoizeFastEquals = microMemoize(fibonacciSingleObject, { | ||
isEqual: fastEquals | ||
}); | ||
const mMicroMemoizeHashIt = microMemoize(fibonacciMultipleDeepEqual, { | ||
isEqual: hashItEquals | ||
const mMicroMemoizeFastDeepEquals = microMemoize(fibonacciSingleObject, { | ||
isEqual: fastDeepEqual | ||
}); | ||
const mMoizeDeep = moize(fibonacciSingleObject, { | ||
isDeepEqual: true | ||
}); | ||
const mMoizeDeepEquals = moize(fibonacciSingleObject, { | ||
matchesArg: deepEquals | ||
}); | ||
const mMoizeFastEquals = moize(fibonacciSingleObject, { | ||
matchesArg: fastEquals | ||
}); | ||
const mMoizeFastDeepEquals = moize(fibonacciSingleObject, { | ||
matchesArg: fastDeepEqual | ||
}); | ||
const mNanoDeep = nanomemoize(fibonacciMultipleDeepEqual, { | ||
const mNanoDeepEquals = nanomemoize(fibonacciSingleObject, { | ||
equals: deepEquals | ||
}); | ||
const mNanoFastEquals = nanomemoize(fibonacciMultipleDeepEqual, { | ||
const mNanoFastEquals = nanomemoize(fibonacciSingleObject, { | ||
equals: fastEquals | ||
}); | ||
const mNanoFastDeepEquals = nanomemoize(fibonacciMultipleDeepEqual, { | ||
const mNanoFastDeepEquals = nanomemoize(fibonacciSingleObject, { | ||
equals: fastDeepEqual | ||
}); | ||
const mNanoHashIt = nanomemoize(fibonacciMultipleDeepEqual, { | ||
equals: hashItEquals | ||
}); | ||
return new Promise((resolve) => { | ||
fibonacciSuite | ||
.add('nanomemoize deep equals (lodash isEqual)', () => { | ||
mNanoDeep(fibonacciNumber); | ||
mNanoDeepEquals(fibonacciNumber); | ||
}) | ||
.add('nanomemoize fast equals (fast-equals deepEqual/ES6)', () => { | ||
.add('nanomemoize fast equals (fast-equals deep)', () => { | ||
mNanoFastEquals(fibonacciNumber); | ||
}) | ||
.add('nanomemoize fast deep equals (fast-deep-equal/ES6)', () => { | ||
.add('nanomemoize fast equals (fast-deep-equals)', () => { | ||
mNanoFastDeepEquals(fibonacciNumber); | ||
}) | ||
.add('nanomemoize deep equals (hash-it isEqual)', () => { | ||
mNanoHashIt(fibonacciNumber); | ||
}) | ||
.add('micro-memoize deep equals (lodash isEqual)', () => { | ||
mMicroMemoizeDeep(fibonacciNumber); | ||
mMicroMemoizeDeepEquals(fibonacciNumber); | ||
}) | ||
.add('micro-memoize deep equals (fast-equals deepEqual)', () => { | ||
mMicroMemoizeFastDeep(fibonacciNumber); | ||
.add('micro-memoize deep equals (fast-equals)', () => { | ||
mMicroMemoizeFastEquals(fibonacciNumber); | ||
}) | ||
.add('micro-memoize deep equals (hash-it isEqual)', () => { | ||
mMicroMemoizeHashIt(fibonacciNumber); | ||
.add('micro-memoize deep equals (fast-deep-equal)', () => { | ||
mMicroMemoizeFastDeepEquals(fibonacciNumber); | ||
}) | ||
.add('moize deep (internal)', () => { | ||
mMoizeDeep(fibonacciNumber); | ||
}) | ||
.add('moize deep equals (lodash isEqual)', () => { | ||
mMoizeDeepEquals(fibonacciNumber); | ||
}) | ||
.add('moize deep equals (fast-equals)', () => { | ||
mMoizeFastEquals(fibonacciNumber); | ||
}) | ||
.add('moize deep equals (fast-deep-equal)', () => { | ||
mMoizeFastEquals(fibonacciNumber); | ||
}) | ||
.on('start', () => { | ||
@@ -529,2 +648,3 @@ console.log(''); // eslint-disable-line no-console | ||
.then(runMultipleObjectSuite) | ||
.then(runMultipleMixedSuite) | ||
.then(runAlternativeOptionsSuite); |
{ | ||
"name": "nano-memoize", | ||
"version": "v3.0.8", | ||
"version": "v3.0.9", | ||
"description": "Faster than fast, smaller than micro ... a nano speed and nano size memoizer.", | ||
@@ -5,0 +5,0 @@ "type:": "module", |
214
README.md
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/30ce201484754fa5b0a6c6046abb842d)](https://www.codacy.com/app/syblackwell/nano-memoize?utm_source=github.com&utm_medium=referral&utm_content=anywhichway/nano-memoize&utm_campaign=Badge_Grade) | ||
# Faster than fast, smaller than micro ... nano-memoize. | ||
# Faster than fast, smaller than micro ... nano-memoizer. | ||
@@ -22,2 +22,4 @@ # Introduction | ||
* For a real world simulation where only 20% of the function calls are memoized and they take mixed argument types, `nanomemoize` remains the fastest. Although, it is within the margin of error for `fastMemoize` | ||
The `planetheidea/moize` library (which claims to be the fastest on average) does not include `nano-memoize` for comparison and the repository is not accepting comments or a pull request for some technical reason. The repository has been forked and its own benchmarking has been updated and run to confirm the results below. | ||
@@ -27,120 +29,92 @@ | ||
Starting cycles for functions with a single primitive parameter... | ||
``` | ||
┌───────────────┬─────────────┬──────────────────────────┬─────────────┐ | ||
│ Name │ Ops / sec │ Relative margin of error │ Sample size │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nano-memoize │ 150,014,960 │ ± 1.26% │ 88 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ fast-memoize │ 148,920,057 │ ± 1.37% │ 88 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize │ 148,405,982 │ ± 1.46% │ 90 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ iMemoized │ 117,844,380 │ ± 1.65% │ 88 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ moize │ 96,796,008 │ ± 1.80% │ 85 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ underscore │ 54,815,804 │ ± 1.28% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ lodash │ 54,617,110 │ ± 1.30% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ lru-memoize │ 41,426,130 │ ± 1.16% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizee │ 31,747,590 │ ± 1.52% │ 85 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ addy-osmani │ 14,848,551 │ ± 1.76% │ 82 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizerific │ 12,835,863 │ ± 1.84% │ 85 │ | ||
└───────────────┴─────────────┴──────────────────────────┴─────────────┘ | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| nano-memoize | 150,014,960 | ± 1.26% | 88 | | ||
| fast-memoize | 148,920,057 | ± 1.37% | 88 | | ||
| micro-memoize | 148,405,982 | ± 1.46% | 90 | | ||
| iMemoized | 117,844,380 | ± 1.65% | 88 | | ||
| moize | 96,796,008 | ± 1.80% | 85 | | ||
| underscore | 54,815,804 | ± 1.28% | 87 | | ||
| lodash | 54,617,110 | ± 1.30% | 87 | | ||
| lru-memoize | 41,426,130 | ± 1.16% | 87 | | ||
| memoizee | 31,747,590 | ± 1.52% | 85 | | ||
| addy-osmani | 14,848,551 | ± 1.76% | 82 | | ||
| memoizerific | 12,835,863 | ± 1.84% | 85 | | ||
Starting cycles for functions with a single object parameter... | ||
┌───────────────┬─────────────┬──────────────────────────┬─────────────┐ | ||
│ Name │ Ops / sec │ Relative margin of error │ Sample size │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nano-memoize │ 149,402,848 │ ± 1.20% │ 90 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ fast-memoize │ 121,117,510 │ ± 2.41% │ 86 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ iMemoized │ 98,480,257 │ ± 3.36% │ 85 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize │ 97,781,728 │ ± 1.36% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ moize │ 94,370,945 │ ± 4.58% │ 84 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ lodash │ 41,298,824 │ ± 2.60% │ 84 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ lru-memoize │ 39,315,541 │ ± 1.55% │ 86 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ underscore │ 33,803,044 │ ± 1.66% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizee │ 27,298,946 │ ± 2.40% │ 86 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ addy-osmani │ 16,003,489 │ ± 1.72% │ 87 │ | ||
├───────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizerific │ 12,502,443 │ ± 1.33% │ 86 │ | ||
└───────────────┴─────────────┴──────────────────────────┴─────────────┘ | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| nano-memoize | 149,402,848 | ± 1.20% | 90 | | ||
| fast-memoize | 121,117,510 | ± 2.41% | 86 | | ||
| iMemoized | 98,480,257 | ± 3.36% | 85 | | ||
| micro-memoize | 97,781,728 | ± 1.36% | 87 | | ||
| moize | 94,370,945 | ± 4.58% | 84 | | ||
| lodash | 41,298,824 | ± 2.60% | 84 | | ||
| lru-memoize | 39,315,541 | ± 1.55% | 86 | | ||
| underscore | 33,803,044 | ± 1.66% | 87 | | ||
| memoizee | 27,298,946 | ± 2.40% | 86 | | ||
| addy-osmani | 16,003,489 | ± 1.72% | 87 | | ||
| memoizerific | 12,502,443 | ± 1.33% | 86 | | ||
Starting cycles for functions with multiple parameters that contain only primitives... | ||
┌───────────────┬────────────┬──────────────────────────┬─────────────┐ | ||
│ Name │ Ops / sec │ Relative margin of error │ Sample size │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ nano-memoize │ 57,333,928 │ ± 1.83% │ 85 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize │ 51,539,993 │ ± 2.07% │ 83 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ moize │ 49,918,411 │ ± 3.30% │ 81 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ lru-memoize │ 29,594,676 │ ± 2.83% │ 79 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizee │ 17,895,742 │ ± 2.08% │ 87 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ iMemoized │ 12,263,731 │ ± 1.99% │ 85 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizerific │ 7,804,227 │ ± 1.81% │ 84 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ addy-osmani │ 4,190,503 │ ± 2.03% │ 84 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ fast-memoize │ 1,101,952 │ ± 2.87% │ 81 │ | ||
└───────────────┴────────────┴──────────────────────────┴─────────────┘ | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| nano-memoize | 57,333,928 | ± 1.83% | 85 | | ||
| micro-memoize | 51,539,993 | ± 2.07% | 83 | | ||
| moize | 49,918,411 | ± 3.30% | 81 | | ||
| lru-memoize | 29,594,676 | ± 2.83% | 79 | | ||
| memoizee | 17,895,742 | ± 2.08% | 87 | | ||
| iMemoized | 12,263,731 | ± 1.99% | 85 | | ||
| memoizerific | 7,804,227 | ± 1.81% | 84 | | ||
| addy-osmani | 4,190,503 | ± 2.03% | 84 | | ||
| fast-memoize | 1,101,952 | ± 2.87% | 81 | | ||
Starting cycles for functions with multiple parameters that contain objects... | ||
┌───────────────┬────────────┬──────────────────────────┬─────────────┐ | ||
│ Name │ Ops / sec │ Relative margin of error │ Sample size │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize │ 51,551,926 │ ± 2.10% │ 82 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ nano-memoize │ 40,243,156 │ ± 3.75% │ 82 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ moize │ 37,285,146 │ ± 16.13% │ 65 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ lru-memoize │ 27,946,905 │ ± 3.41% │ 79 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizee │ 17,209,457 │ ± 1.96% │ 84 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ memoizerific │ 7,609,760 │ ± 4.26% │ 76 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ addy-osmani │ 1,212,045 │ ± 1.85% │ 86 │ | ||
├───────────────┼────────────┼──────────────────────────┼─────────────┤ | ||
│ fast-memoize │ 563,610 │ ± 26.34% │ 69 │ | ||
└───────────────┴────────────┴──────────────────────────┴─────────────┘ | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| micro-memoize | 51,551,926 | ± 2.10% | 82 | | ||
| nano-memoize | 40,243,156 | ± 3.75% | 82 | | ||
| moize | 37,285,146 | ± 16.13% | 65 | | ||
| lru-memoize | 27,946,905 | ± 3.41% | 79 | | ||
| memoizee | 17,209,457 | ± 1.96% | 84 | | ||
| memoizerific | 7,609,760 | ± 4.26% | 76 | | ||
| addy-osmani | 1,212,045 | ± 1.85% | 86 | | ||
| fast-memoize | 563,610 | ± 26.34% | 69 | | ||
Starting cycles for alternative cache types... | ||
┌─────────────────────────────────────────────────────┬─────────────┬──────────────────────────┬─────────────┐ | ||
│ Name │ Ops / sec │ Relative margin of error │ Sample size │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nanomemoize deep equals (hash-it isEqual) │ 112,560,448 │ ± 1.35% │ 85 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize deep equals (lodash isEqual) │ 83,402,392 │ ± 2.88% │ 80 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize deep equals (hash-it isEqual) │ 70,493,317 │ ± 2.46% │ 83 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nanomemoize deep equals (lodash isEqual) │ 63,040,211 │ ± 1.61% │ 84 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nanomemoize fast equals (fast-equals deepEqual/ES6) │ 61,878,364 │ ± 1.73% │ 84 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ micro-memoize deep equals (fast-equals deepEqual) │ 56,841,180 │ ± 3.10% │ 80 │ | ||
├─────────────────────────────────────────────────────┼─────────────┼──────────────────────────┼─────────────┤ | ||
│ nanomemoize fast deep equals (fast-deep-equal/ES6) │ 41,010,681 │ ± 2.44% │ 82 │ | ||
└─────────────────────────────────────────────────────┴─────────────┴──────────────────────────┴─────────────┘ | ||
``` | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| nanomemoize deep equals (hash-it isEqual) | 107,990,728 | ± 2.59% | 83 | | ||
| nanomemoize deep equals (lodash isEqual) | 96,543,576 | ± 2.20% | 84 | | ||
| moize deep equals (lodash isEqual) | 88,305,997 | ± 2.55% | 82 | | ||
| micro-memoize deep equals (fast-equals) | 86,511,616 | ± 1.67% | 85 | | ||
| moize deep equals (fast-deep-equal) | 85,948,355 | ± 1.55% | 79 | | ||
| micro-memoize deep equals (lodash isEqual) | 85,231,542 | ± 1.83% | 84 | | ||
| moize deep equals (fast-equals) | 84,844,833 | ± 1.77% | 85 | | ||
| moize deep equals (hash-it isEqual) | 76,605,158 | ± 1.82% | 83 | | ||
| micro-memoize deep equals (hash-it isEqual) | 73,619,713 | ± 2.26% | 82 | | ||
| nanomemoize fast equals (fast-equals deep) | 64,710,177 | ± 1.59% | 79 | | ||
| micro-memoize deep equals (fast-deep-equal) | 62,658,012 | ± 2.95% | 78 | | ||
| nanomemoize fast equals (fast-deep-equals) | 42,443,623 | ± 1.91% | 82 | | ||
Starting real world simulation... | ||
| Name | Ops / sec | Relative margin of error | Sample size | | ||
| ------- |------- |------------- |------- | | ||
| nanomemoizedFunction | 3,456,663 | ± 1.10% | 92 | | ||
| fastmoizedFunction | 3,453,148 | ± 1.69% | 92 | | ||
| microMemoizedFunction | 1,833,970 | ± 0.80% | 95 | | ||
| moizeMemoizedFunction | 1,810,871 | ± 0.49% | 93 | | ||
If you want similar performance for intersection, union or Cartesian product also see: | ||
@@ -152,3 +126,3 @@ | ||
For a complete high performance solution to Cartesian product and set operations for Arrays and Sets with a standardized API, plus the addition of the standard map/reduce/find operations to Set see: | ||
For a complete high performance solution to Cartesian product and set operations for Arrays and Sets with a standardized API, plus the addition of the standard map/reduce/find operations to Set see: | ||
@@ -209,19 +183,21 @@ - https://github.com/anywhichway/array-set-ops | ||
2022-02-22 v3.0.8 Documentation updates. | ||
2023-04-07 v3.0.9 Added real world simulation. Removed .parcel-cache from deployment. | ||
2022-02-15 v3.0.7 Documentation updates. | ||
2023-02-22 v3.0.8 Documentation updates. | ||
2022-02-15 v3.0.6 Documentation updates. | ||
2023-02-15 v3.0.7 Documentation updates. | ||
2022-02-15 v3.0.5 Documentation updates. | ||
2023-02-15 v3.0.6 Documentation updates. | ||
2022-02-04 v3.0.4 A code walkthrough revealed an opportunity to remove unused code from v2.x.x. | ||
2023-02-15 v3.0.5 Documentation updates. | ||
2022-02-02 v3.0.3 Added unit test for `maxAge`. Adjusted varArg unit tests for more accuracy. Slight optimizations to multi argument memoized functions. Slight improvement to cache clearing that may reduce GC. Updated license file for copyright period. Updated docs on `callTimeout` for clarity. | ||
2023-02-04 v3.0.4 A code walkthrough revealed an opportunity to remove unused code from v2.x.x. | ||
2022-02-01 v3.0.2 Fixed https://github.com/anywhichway/nano-memoize/issues/52 with custom equals functions not consistently working. `fast-equals` or `lodash.isEqual` now work. Slight performance degradation, but still generally the fastest. | ||
2023-02-02 v3.0.3 Added unit test for `maxAge`. Adjusted varArg unit tests for more accuracy. Slight optimizations to multi argument memoized functions. Slight improvement to cache clearing that may reduce GC. Updated license file for copyright period. Updated docs on `callTimeout` for clarity. | ||
2023-02-01 v3.0.2 Fixed https://github.com/anywhichway/nano-memoize/issues/52 with custom equals functions not consistently working. `fast-equals` or `lodash.isEqual` now work. Slight performance degradation, but still generally the fastest. | ||
2022-01-29 v3.0.1 Fixed build issue where root index.js was not getting updated. | ||
2022-01-28 v3.0.0 Slight size optimization. 25% speed improvement. Moved to module format. There is a known issue with providing `fast-equals` or `lodash.isEqual` as an optional comparison function. Unit tests pass, but the functions fail under load. The `hash-it` object equivalence function does work. A formerly undocumented method `.keyValues()` has been deprecated since it is no longer relevant with the new optimizations. | ||
2023-01-28 v3.0.0 Slight size optimization. 25% speed improvement. Moved to module format. There is a known issue with providing `fast-equals` or `lodash.isEqual` as an optional comparison function. Unit tests pass, but the functions fail under load. The `hash-it` object equivalence function does work. A formerly undocumented method `.keyValues()` has been deprecated since it is no longer relevant with the new optimizations. | ||
@@ -228,0 +204,0 @@ 2022-12-08 v2.0.0 Removed callTimeout from TypeScript typings since it was not implemented and there are no plans to implement. Bumped version to 2.0.0 since this may break some users. |
@@ -71,9 +71,9 @@ /* | ||
// looking at each arg separately so a test can abort as soon as possible | ||
f = function() { | ||
var l = maxargs||arguments.length, kl = k.length, i =-1; | ||
f = function(...argv) { | ||
var l = maxargs||argv.length, kl = k.length, i =-1; | ||
while(++i<kl) { // k is an array of arrays of args, each array represents a call signature | ||
var args = k[i]; | ||
if (maxargs!=null || args.length === l) { | ||
if (args.length === l) { // maxargs!=null || | ||
var j = -1; | ||
while (++j < l && (eq ? eq(arguments[j], args[j]) : arguments[j]===args[j])) { }// compare each arg | ||
while (++j < l && (eq ? eq(argv[j], args[j]) : argv[j]===args[j])) { }// compare each arg | ||
if (j === l) return v[i] //the args matched; | ||
@@ -83,3 +83,3 @@ } | ||
// set change timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
return (!c||c(i)),v[i] = fn.apply(this,k[i] = arguments); | ||
return (!c||c(i)),v[i] = fn.apply(this,k[i] = argv); | ||
} | ||
@@ -86,0 +86,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 5 instances in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1261
1
90820
21
279
2