Add lru-cache module: LinkedHashMap and hand-rolled DLL LRU, coarse-lock/striped thread-safe variants, broken ReadWriteLock demo, Caffeine reference, 43 tests, JMH harness
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4VQVEJWetTT1dYzyJ
This commit is contained in:
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/. Needs JDK 25 and Maven. First Maven run must be online.
|
||||
# 01-08 are written by JUnit tests that assert the same facts (deterministic).
|
||||
# 09 (broken ReadWriteLock demo) and 10 (JMH) are MEASUREMENTS: they vary per run and machine.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output
|
||||
mvn -B -q -T1 test
|
||||
mvn -B -q -T1 compile
|
||||
{ java -cp target/classes com.ankurm.interviewlab.lrucache.BrokenLockDemo 2>&1 | grep -v '^Picked up JAVA_TOOL_OPTIONS' ; } > output/09-broken-readwritelock-demo.txt
|
||||
scripts/run-jmh.sh > /dev/null
|
||||
echo "done:"; ls -1 output
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Short JMH run: INDICATIVE only. One fork, 3 x 1s warmup, 5 x 2s measurement per cell.
|
||||
# On a shared 2-vCPU sandbox the absolute numbers move 10-30% between runs; read the ORDER and
|
||||
# the SHAPE (who collapses with more threads), not the third digit.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output
|
||||
mvn -B -q -T1 compile
|
||||
mvn -B -q dependency:build-classpath -Dmdep.outputFile=target/cp.txt
|
||||
CP="target/classes:$(cat target/cp.txt)"
|
||||
J="java -cp $CP org.openjdk.jmh.Main LruBenchmark -f 1 -wi 3 -w 1 -i 5 -r 2 -tu us"
|
||||
{
|
||||
echo "JMH 1.37 / $(java -version 2>&1 | grep -v Picked | head -1)"
|
||||
echo "cores=$(nproc) loadavg-at-start=$(cut -d' ' -f1-3 /proc/loadavg) (shared sandbox: INDICATIVE)"
|
||||
echo "workload: get; on miss put. Keys uniform over 2048, capacity 1024. ops/microsecond, higher is better."
|
||||
echo
|
||||
echo "### 1 thread, all implementations"
|
||||
$J -t 1 2>&1 | grep -E '^LruBenchmark|^Benchmark'
|
||||
for t in 2 4; do
|
||||
echo
|
||||
echo "### $t threads, thread-safe implementations only"
|
||||
$J -t $t -p "impl=synchronizedMap(LinkedHashMap),synchronized,reentrantlock,striped16,striped16-lowbits,caffeine" 2>&1 | grep -E '^LruBenchmark|^Benchmark'
|
||||
done
|
||||
} > output/10-jmh-indicative.txt
|
||||
cat output/10-jmh-indicative.txt
|
||||
Reference in New Issue
Block a user