Skip to content

feat(cpp): add binarytrees benchmark (1.cpp) - #507

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

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

Conversation

@bonnhatnguyen

Copy link
Copy Markdown

Description

Adds the first C++ implementation (1.cpp) for the binarytrees benchmark, enabling C++ on the leaderboard.

Key Architectural Highlights

  • Thread-Local Reusable Bump Allocator Arena: Instead of incurring thousands of expensive individual heap allocations via new/malloc and individual recursive deallocations, each worker thread retains a pre-sized contiguous memory buffer.
  • O(1) Instant Arena Reset: After each tree is constructed and its checksum is evaluated, the arena pointer is reset in $O(1)$ (offset = 0), completely eliminating GC and deallocation overhead.
  • OpenMP Guided Parallel Scheduling: Subtrees are distributed across available cores using #pragma omp parallel for reduction(+:chk) schedule(guided) for maximum core utilization.

Verification & Benchmark

  • Verified against unit tests:
    • 6 -> 6_out (Match OK)
    • 10 -> 10_out (Match OK)
  • Benchmark runtime on depth 18 (18):
    • ~0.17s real time (~1.87s user time across cores), outperforming existing GC and heap-allocated implementations by >15x.

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