slim-cache
Super Fast Lightweight Cache with a Map like interface
Highlights
-
Super Fast
-
Written in Typescript
-
Easy Map Like Interface
Usage
Super Fast Lightweight Cache with a Map like interface
; cache = ; // creates new cache cache; cache; // 'world' cache; // true cacheclear'hello'; //true cache; // true cache; cache; // Clears every key of the cache rendering it empty cache; // true cache; // replaces internal cache object with user provided object cache; // cache
Benchmark
All benchmarks were run using benchmark
Memoization
fast-memoize was used with various caches to memoize a standard recursive fibonacci function
Benchmark was run for all the memoized functions to find 40th fibonacci number
┌──────────────┬─────────────┬──────────────────────────┬─────────────┐│ NAME │ OPS/SEC │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ slim-cache │ 402727692 │ ± 035% │ 93 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ object cache │ 391995589 │ ± 061% │ 94 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ map-cache │ 388972451 │ ± 158% │ 92 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ fast-memoize │ 334922846 │ ± 035% │ 91 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ native map │ 265225627 │ ± 056% │ 90 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ vanilla │ 1 │ ± 691% │ 7 │└──────────────┴─────────────┴──────────────────────────┴─────────────┘
Legend
-
slim-cache : fibonacci function memoized using fast-memoize with SlimCache instance
-
object cache: fibonacci function memoized using fast-memoize with Empty Object based cache
-
map-cache: fibonacci function memoized using fast-memoize with MapCache instance
-
fast-memoize: default fast-memoize cache
-
native map: fibonacci function memoized using fast-memoize with Native ES6 Map based cache
-
vanilla: fibonacci function without memoization
Methods
has
┌────────────┬─────────────┬──────────────────────────┬─────────────┐│ NAME │ OPS/SEC │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ slim-cache │ 902468492 │ ± 163% │ 93 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ native map │ 694384457 │ ± 062% │ 95 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ map-cache │ 686595656 │ ± 074% │ 90 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ object │ 184851669 │ ± 327% │ 86 │└────────────┴─────────────┴──────────────────────────┴─────────────┘
get
┌────────────┬─────────────┬──────────────────────────┬─────────────┐│ NAME │ OPS/SEC │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ slim-cache │ 917775700 │ ± 042% │ 94 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ map-cache │ 914493164 │ ± 046% │ 92 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ object │ 913072253 │ ± 054% │ 91 │├────────────┼─────────────┼──────────────────────────┼─────────────┤│ native map │ 667015102 │ ± 169% │ 91 │└────────────┴─────────────┴──────────────────────────┴─────────────┘
set
┌──────────────┬─────────────┬──────────────────────────┬─────────────┐│ NAME │ OPS/SEC │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ object cache │ 916023083 │ ± 039% │ 96 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ slim-cache │ 912787773 │ ± 050% │ 94 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ map-cache │ 911402606 │ ± 056% │ 96 │├──────────────┼─────────────┼──────────────────────────┼─────────────┤│ native map │ 144171162 │ ± 048% │ 91 │└──────────────┴─────────────┴──────────────────────────┴─────────────┘
License
MIT © Nivrith Mandayam Gomatam