@@ -16,6 +16,7 @@ This directory contains modern benchmark implementations for the tiny-lru librar
1616 - Realistic workload scenarios without measuring setup/teardown
1717
1818** Test Categories** :
19+
1920- SET operations (empty cache, full cache, eviction scenarios)
2021- GET operations (hit/miss patterns, access patterns)
2122- Mixed operations (real-world 80/20 read-write scenarios)
@@ -26,7 +27,7 @@ This directory contains modern benchmark implementations for the tiny-lru librar
2627
2728** Comprehensive comparison against other popular LRU cache libraries**
2829
29- - ** Libraries Tested** :
30+ - ** Libraries Tested** :
3031 - ` tiny-lru ` (this library)
3132 - ` lru-cache ` (most popular npm LRU implementation)
3233 - ` quick-lru ` (fast, lightweight alternative)
@@ -39,6 +40,7 @@ This directory contains modern benchmark implementations for the tiny-lru librar
3940 - Multiple operations per measured callback to reduce harness overhead
4041
4142** Test Categories** :
43+
4244- SET operations across all libraries
4345- GET operations with pre-populated caches
4446- DELETE operations comparison
@@ -59,6 +61,7 @@ This directory contains modern benchmark implementations for the tiny-lru librar
5961 - Deterministic mixed workloads (no ` Math.random() ` in measured loops)
6062
6163** Test Categories** :
64+
6265- Performance Observer based function timing
6366- Custom timer with statistical analysis
6467- Scalability tests (100 to 10,000 cache sizes)
@@ -111,6 +114,7 @@ node benchmarks/comparison-benchmark.js
111114## Understanding the Results
112115
113116### Tinybench Output
117+
114118```
115119┌─────────┬─────────────────────────────┬─────────────────┬────────────────────┬──────────┬─────────┐
116120│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
@@ -124,6 +128,7 @@ node benchmarks/comparison-benchmark.js
124128- ** Samples** : Number of samples collected for statistical significance
125129
126130### Performance Observer Output
131+
127132```
128133┌─────────────┬─────────┬────────────┬────────────┬────────────┬───────────────┬─────────┬────────┐
129134│ Function │ Calls │ Avg (ms) │ Min (ms) │ Max (ms) │ Median (ms) │ Std Dev │Ops/sec │
@@ -132,6 +137,7 @@ node benchmarks/comparison-benchmark.js
132137```
133138
134139### Comparison Benchmark Output
140+
135141```
136142📊 SET Operations Benchmark
137143┌─────────┬─────────────────────────────┬─────────────────┬────────────────────┬──────────┬─────────┐
@@ -155,71 +161,88 @@ Memory Usage Results:
155161## Benchmark Categories Explained
156162
157163### SET Operations
164+
158165Tests cache write performance under various conditions:
166+
159167- ** Empty cache** : Setting items in a fresh cache
160168- ** Full cache** : Setting items when cache is at capacity (triggers eviction)
161169- ** Random vs Sequential** : Different access patterns
162-
170+
163171Implementation details:
172+
164173- Deterministic keys/values are pre-generated once per run
165174- Access indices are precomputed via a fast PRNG (xorshift) to avoid runtime randomness
166175- Multiple operations are executed per benchmark callback to minimize harness overhead
167176
168- ### GET Operations
177+ ### GET Operations
178+
169179Tests cache read performance:
180+
170181- ** Cache hits** : Reading existing items
171182- ** Cache misses** : Reading non-existent items
172183- ** Mixed patterns** : Realistic 80% hit / 20% miss scenarios
173-
184+
174185Implementation details:
186+
175187- Caches are pre-populated outside the measured section
176188- Access indices are precomputed; no ` Math.random() ` inside measured loops
177189
178190### Mixed Operations
191+
179192Real-world usage simulation:
193+
180194- ** 80/20 read-write** : Typical web application pattern
181195- ** Cache warming** : Sequential population scenarios
182196- ** High churn** : Frequent eviction scenarios
183197- ** LRU access patterns** : Testing LRU algorithm efficiency
184-
198+
185199Implementation details:
200+
186201- Choice and index streams are precomputed
187202- No wall-clock calls (` Date.now ` ) inside hot paths
188203
189204### Special Operations
205+
190206Edge cases and additional functionality:
207+
191208- ** Delete operations** : Individual item removal
192209- ** Clear operations** : Complete cache clearing
193210- ** Different data types** : Numbers, objects, strings
194211- ** Memory usage** : Heap consumption analysis
195-
212+
196213Implementation details:
214+
197215- Delete benchmarks maintain a steady state by re-adding deleted keys to keep cardinality stable
198216
199217## Best Practices Implemented
200218
201219### 1. Statistical Significance
220+
202221- Minimum execution time (1 second) for reliable results
203222- Multiple iterations for statistical validity
204223- Standard deviation and margin of error reporting
205224
206225### 2. Realistic Test Data
226+
207227- Variable key/value sizes mimicking real applications
208228- Deterministic pseudo-random and sequential access patterns (precomputed)
209229- Pre-population scenarios for realistic cache states
210230
211231### 3. Multiple Measurement Approaches
232+
212233- ** Tinybench** : Modern, accurate micro-benchmarking
213234- ** Performance Observer** : Native Node.js function timing
214235- ** Custom timers** : High-resolution manual timing
215236
216237### 4. Comprehensive Coverage
238+
217239- Different cache sizes (100, 1K, 5K, 10K)
218240- Various workload patterns
219241- Memory consumption analysis
220242- Edge case testing
221243
222244### 5. Methodology Improvements (Current)
245+
223246- Setup/teardown moved outside measured sections to avoid skewing results
224247- Deterministic data and access patterns (no randomness in hot paths)
225248- Batched operations per invocation reduce harness overhead reliably across tasks
@@ -228,27 +251,31 @@ Implementation details:
228251## Performance Tips
229252
230253### For accurate results:
254+
2312551 . ** Close other applications** to reduce system noise
2322562 . ** Run multiple times** and compare results
2332573 . ** Use consistent hardware** for comparisons
2342584 . ** Enable garbage collection** with ` --expose-gc ` for memory tests
2352595 . ** Consider CPU frequency scaling** on laptops
236260
237261### Environment information included:
262+
238263- Node.js version
239- - Platform and architecture
264+ - Platform and architecture
240265- Timestamp for result tracking
241266
242267## Interpreting Results
243268
244269### Good Performance Indicators:
270+
245271- ✅ ** Consistent ops/sec** across runs
246272- ✅ ** Low margin of error** (< 5%)
247273- ✅ ** Reasonable standard deviation**
248274- ✅ ** GET operations faster than SET**
249275- ✅ ** Cache hits faster than misses**
250276
251277### Warning Signs:
278+
252279- ⚠️ ** High margin of error** (> 10%)
253280- ⚠️ ** Widely varying results** between runs
254281- ⚠️ ** Memory usage growing unexpectedly**
@@ -260,16 +287,17 @@ To add new benchmark scenarios:
260287
261288``` javascript
262289// In modern-benchmark.js
263- bench .add (' your-test-name' , () => {
290+ bench .add (" your-test-name" , () => {
264291 // Your test code here
265292 const cache = lru (1000 );
266- cache .set (' key' , ' value' );
293+ cache .set (" key" , " value" );
267294});
268295```
269296
270297## Contributing
271298
272299When adding new benchmarks:
300+
2733011 . Follow the existing naming conventions
2743022 . Include proper setup/teardown
2753033 . Add statistical significance checks
@@ -279,6 +307,7 @@ When adding new benchmarks:
279307## Benchmark Results Archive
280308
281309Consider saving benchmark results with:
310+
282311``` bash
283312# Save all benchmark results
284313npm run benchmark:all > results/benchmark-$( date +%Y%m%d-%H%M%S) .txt
@@ -296,19 +325,22 @@ This helps track performance improvements/regressions over time.
296325Choose the right benchmark for your needs:
297326
298327### Use ` modern-benchmark.js ` when:
328+
299329- ✅ You want comprehensive analysis of tiny-lru performance
300330- ✅ You need statistical significance and margin of error data
301331- ✅ You're testing different cache sizes and workload patterns
302332- ✅ You want realistic scenario testing
303333
304334### Use ` comparison-benchmark.js ` when:
335+
305336- ✅ You're evaluating tiny-lru against other LRU libraries
306337- ✅ You need bundle size and memory usage comparisons
307338- ✅ You want to see competitive performance analysis
308339- ✅ You're making library selection decisions
309340
310341### Use ` performance-observer-benchmark.js ` when:
342+
311343- ✅ You need native Node.js performance measurement
312344- ✅ You want function-level timing analysis
313345- ✅ You're testing scalability across different cache sizes
314- - ✅ You prefer Performance API over external libraries
346+ - ✅ You prefer Performance API over external libraries
0 commit comments