Benchmark and Performance

Table of Contents

Environment

Latest local run:

FieldValue
Date2026-06-11
Node.jsv20.20.2
OS / Archwin32 x64
CPUIntel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Redisredis://127.0.0.1:6379
Package versionflex-rate-limit@2.2.4 working tree

These numbers are local-machine measurements, not portable product claims.

Current Memory Benchmark

Command:

$env:BENCH_JSON='1'
$env:BENCH_RUNS='5'
$env:BENCH_ITERATIONS='200000'
$env:BENCH_KEYS='1000'
npm run benchmark:memory
AlgorithmMedian ops/sRange ops/s
fixed-window1,000,695758,579-1,177,554
sliding-window1,488,5181,116,897-1,964,677
token-bucket1,150,445849,225-1,374,173
leaky-bucket1,033,670868,372-1,224,991

Memory OSS Comparison

The OSS comparison uses the historical local script in .devcodex/flex-rate-limit/tmp/oss-rate-limit-bench-20260531/compare-oss.cjs.

100,000 checks / 1,000 keys

ImplementationMedian ops/s
flex sliding-window2,137,273
limiter keyed token bucket1,821,318
rate-limiter-flexible memory1,755,547
express-rate-limit memory middleware559,102

200,000 checks / 5,000 keys

ImplementationMedian ops/s
flex sliding-window2,085,832
limiter keyed token bucket1,146,367
rate-limiter-flexible memory865,127
express-rate-limit memory middleware314,179

100,000 checks / 1 hot key

ImplementationMedian ops/s
flex sliding-window3,236,078
rate-limiter-flexible memory3,112,453
flex leaky-bucket2,507,171
limiter keyed token bucket2,115,614
express-rate-limit memory middleware544,788

Redis Direct Benchmark

Command:

$env:BENCH_JSON='1'
$env:BENCH_ITERATIONS='5000'
$env:BENCH_KEYS='500'
$env:BENCH_CONCURRENCY='1,32'
npm run benchmark:redis
StoreAlgorithmc=1 ops/sc=32 ops/s
RedisStorefixed-window9,69833,458
CacheHubStorefixed-window9,25540,465
RedisStoresliding-window6,84014,684
CacheHubStoresliding-window7,84729,482
RedisStoretoken-bucket6,04715,451
CacheHubStoretoken-bucket9,39044,921
RedisStoreleaky-bucket6,30118,631
CacheHubStoreleaky-bucket8,91146,160
rate-limiter-flexiblefixed-window8,18320,072

HTTP Middleware Benchmark

Command:

$env:BENCH_JSON='1'
$env:BENCH_DURATION='5'
$env:BENCH_CONNECTIONS='50'
$env:BENCH_KEYS='500'
npm run benchmark:http
Scenarioreq/sp50p99
flex-redis3,53113 ms34 ms
flex-cache-hub3,50113 ms27 ms
flex-memory3,15113 ms46 ms
rate-limiter-flexible2,77115 ms52 ms

Run the Benchmarks

npm run benchmark:memory
npm run benchmark:redis
npm run benchmark:http

Set BENCH_JSON=1 for machine-readable output. Redis benchmarks skip cleanly if Redis is unavailable.

Reading the Numbers

  • Use Memory results for single-process direct check() hot paths.
  • Use Redis direct results for distributed counter overhead.
  • Use HTTP results for Express-style middleware overhead.
  • Do not compare these numbers to production traffic without matching Node.js, CPU, Redis topology, concurrency, key distribution, and application work.