Skip to content

feat(cpp): add lru benchmark (1.cpp) - #506

Open
bonnhatnguyen wants to merge 1 commit into
hanabi1224:mainfrom
bonnhatnguyen:cpp-lru-cache-1
Open

bonnhatnguyen wants to merge 1 commit into
hanabi1224:mainfrom
bonnhatnguyen:cpp-lru-cache-1

Conversation

@bonnhatnguyen

Copy link
Copy Markdown

Description

Adds the first C++ implementation (1.cpp) for the lru (Least Recently Used) cache benchmark, enabling C++ on the leaderboard.

Key Architectural Highlights

  • Flat-Array Intrusive Doubly-Linked List + Hash Buckets: Uses contiguous flat vectors with 32-bit indices (nodes and buckets) rather than pointer chasing or separate allocations per node.
  • Zero Allocations During Benchmark Loop: Memory for the maximum required capacity is preallocated upfront. All put and get operations run with zero heap allocations.
  • L1-Cache Resident: With capacity $N \le 1,000$, the entire cache metadata fits comfortably inside L1 data cache (< 32 KB), ensuring near-instant cache hits and maximum memory bandwidth efficiency.
  • Fibonacci Multiplicative Hashing: Power-of-two mask indexing with (key * 2654435761u) & mask providing excellent distribution and minimal collision chaining.

Verification & Benchmark

  • Verified against all unit tests:
    • 10 1000 -> 10_1000_out (Match OK)
    • 77 7777 -> 77_7777_out (Match OK)
    • 100 10000 -> 100_10000_out (Match OK)
  • Benchmark runtime on largest workload (1000 3000000 - 3,000,000 operations):
    • ~0.07s user time (~42.8 million operations/second)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant