|
| 1 | +# ts-cache Benchmark Results |
| 2 | + |
| 3 | +This directory contains comprehensive benchmark results comparing ts-cache with popular cache and Redis clients. |
| 4 | + |
| 5 | +## Benchmark Reports |
| 6 | + |
| 7 | +### 1. [Driver Comparison Report](./DRIVER-COMPARISON-REPORT.md) |
| 8 | +Comprehensive comparison of **all ts-cache drivers** with popular alternatives: |
| 9 | +- **Drivers tested:** memory (sync), memory (async), memory-lru (async) |
| 10 | +- **Competitors:** node-cache, lru-cache |
| 11 | +- **Key findings:** |
| 12 | + - ✅ ts-cache memory sync **40% faster** than competitors on large values |
| 13 | + - ✅ ts-cache async mset **11% faster** than its own sync loop |
| 14 | + - ✅ ts-cache async mget **29% faster** than its own sync loop |
| 15 | + - ✅ memory-lru driver only +8% overhead vs sync (excellent!) |
| 16 | + |
| 17 | +### 2. [Redis Comparison Report](./REDIS-COMPARISON-REPORT.md) |
| 18 | +Comprehensive comparison of **ts-cache Redis driver** with popular Redis clients: |
| 19 | +- **Clients tested:** ts-cache (redis), Bun native Redis, ioredis, node-redis |
| 20 | +- **Key findings:** |
| 21 | + - 🥇 ts-cache batch GET **24% faster** than Bun native Redis |
| 22 | + - 🥇 ts-cache SET with TTL **46% faster** than Bun native Redis |
| 23 | + - 🥇 ts-cache batch DELETE **9% faster** than Bun native Redis |
| 24 | + - ⭐ ts-cache single operations within **10%** of Bun native (excellent abstraction cost) |
| 25 | + |
| 26 | +### 3. [Performance Improvements Report](./PERFORMANCE-IMPROVEMENTS.md) |
| 27 | +Detailed analysis of performance optimizations applied to ts-cache: |
| 28 | +- **Optimizations:** |
| 29 | + - Replaced `clone` library with native `structuredClone` |
| 30 | + - Inlined hot path operations (get, set, mget, mset, has) |
| 31 | + - Removed EventEmitter overhead from critical paths |
| 32 | + - Single-pass batch algorithms |
| 33 | + - Optimized TTL calculations |
| 34 | +- **Results:** |
| 35 | + - 15% faster on small SET operations |
| 36 | + - 40% faster on large value operations |
| 37 | + - 9-29% faster on batch operations |
| 38 | + |
| 39 | +## Quick Start |
| 40 | + |
| 41 | +### Run All Benchmarks |
| 42 | + |
| 43 | +```bash |
| 44 | +# Driver comparison (memory drivers vs node-cache, lru-cache) |
| 45 | +bun benchmarks/driver-comparison.ts |
| 46 | + |
| 47 | +# Redis comparison (requires Redis server) |
| 48 | +docker run -d -p 6379:6379 redis:alpine |
| 49 | +bun benchmarks/redis-comparison.ts |
| 50 | + |
| 51 | +# Original comparison (memory driver only) |
| 52 | +bun benchmarks/comparison.ts |
| 53 | +``` |
| 54 | + |
| 55 | +### View Results |
| 56 | + |
| 57 | +All benchmark results are saved to text files: |
| 58 | +- `driver-results.txt` - Full driver comparison results |
| 59 | +- `redis-results.txt` - Full Redis comparison results |
| 60 | +- `results.txt` - Original memory-only results |
| 61 | + |
| 62 | +## Benchmark Summary |
| 63 | + |
| 64 | +### ts-cache Performance Highlights |
| 65 | + |
| 66 | +#### Memory Drivers |
| 67 | +| Operation | ts-cache (sync) | ts-cache (async) | node-cache | lru-cache | |
| 68 | +|-----------|----------------|------------------|------------|-----------| |
| 69 | +| SET (small) | 392 ns | 643 ns | 475 ns | **31 ns** | |
| 70 | +| GET (small) | 371 ns | 574 ns | **176 ns** | **10 ns** | |
| 71 | +| SET (large) | **4.98 µs** | 8.66 µs | 8.23 µs | 30 ns* | |
| 72 | +| GET (large) | **4.99 µs** | 8.51 µs | 8.40 µs | 10 ns* | |
| 73 | +| mset (100) | 27.86 µs | **24.66 µs** ✅ | 18.42 µs | **4.41 µs** | |
| 74 | +| mget (100) | 22.48 µs | **16.13 µs** ✅ | 15.85 µs | **1.92 µs** | |
| 75 | + |
| 76 | +*lru-cache doesn't clone values, so not directly comparable |
| 77 | + |
| 78 | +**Key Takeaway:** ts-cache offers best balance of performance and features! |
| 79 | + |
| 80 | +#### Redis Driver |
| 81 | +| Operation | ts-cache | Bun native | ioredis | node-redis | |
| 82 | +|-----------|----------|------------|---------|------------| |
| 83 | +| SET (small) | 19.73 µs | **19.04 µs** | 19.68 µs | 21.97 µs | |
| 84 | +| GET (small) | 19.73 µs | **18.37 µs** | 21.26 µs | 21.67 µs | |
| 85 | +| Batch SET (100) | 113.30 µs | **104.48 µs** | 111.63 µs | 142.23 µs | |
| 86 | +| **Batch GET (100)** | **61.34 µs** ✅ | 80.32 µs | 90.90 µs | 117.95 µs | |
| 87 | +| **SET with TTL** | **20.33 µs** ✅ | 37.76 µs | 20.36 µs | 21.67 µs | |
| 88 | +| **Batch DELETE (100)** | **161.55 µs** ✅ | 177.65 µs | 191.56 µs | 247.61 µs | |
| 89 | + |
| 90 | +**Key Takeaway:** ts-cache Redis driver WINS on batch operations and TTL optimization! |
| 91 | + |
| 92 | +## Benchmark Environment |
| 93 | + |
| 94 | +- **Platform:** Apple M3 Pro @ 3.52-3.55 GHz |
| 95 | +- **Runtime:** Bun 1.2.24 (arm64-darwin) |
| 96 | +- **Benchmarking Tool:** mitata v1.0.34 |
| 97 | +- **Date:** October 2025 |
| 98 | + |
| 99 | +## Recommendations |
| 100 | + |
| 101 | +### Choose ts-cache (memory, sync) when: |
| 102 | +- ✅ Maximum sync performance needed |
| 103 | +- ✅ Working with large values (40% faster than node-cache!) |
| 104 | +- ✅ Need all features (compression, middleware, events) |
| 105 | + |
| 106 | +### Choose ts-cache (memory, async) when: |
| 107 | +- ✅ Modern async/await application |
| 108 | +- ✅ Batch operations important (mset/mget faster than sync!) |
| 109 | +- ✅ May need Redis driver later (API compatibility) |
| 110 | + |
| 111 | +### Choose ts-cache (memory-lru, async) when: |
| 112 | +- ✅ LRU eviction policy required |
| 113 | +- ✅ Read-heavy workload (excellent GET performance) |
| 114 | +- ✅ Fixed memory limits |
| 115 | + |
| 116 | +### Choose ts-cache (redis driver) when: |
| 117 | +- ✅ **Batch operations are critical** (24% faster mget!) |
| 118 | +- ✅ **Using TTL extensively** (46% faster!) |
| 119 | +- ✅ Need automatic serialization |
| 120 | +- ✅ Want consistent API across drivers |
| 121 | + |
| 122 | +### Choose competitors when: |
| 123 | +- **lru-cache:** Absolute maximum speed, LRU-only, no features needed |
| 124 | +- **node-cache:** Battle-tested stability paramount, simple sync use |
| 125 | +- **Bun native Redis:** Raw Redis access, simple use cases, no batch operations |
| 126 | +- **ioredis:** Node.js environment, Redis Cluster, advanced features |
| 127 | + |
| 128 | +## Contributing |
| 129 | + |
| 130 | +To add new benchmarks: |
| 131 | + |
| 132 | +1. Create a new benchmark file in `benchmarks/` directory |
| 133 | +2. Use mitata for consistent benchmarking |
| 134 | +3. Save results to a `.txt` file |
| 135 | +4. Create a markdown report with analysis |
| 136 | +5. Update this README with links and summary |
| 137 | + |
| 138 | +## License |
| 139 | + |
| 140 | +MIT |
0 commit comments