Skip to content

feat(cpp): add fasta benchmark (1.cpp) - #508

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

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

Conversation

@bonnhatnguyen

@bonnhatnguyen bonnhatnguyen commented Oct 5, 2026 •

Copy link
Copy Markdown

Description

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

Key Architectural Highlights

  • Direct $O(1)$ Lookup Table: Rather than doing linear scanning or binary searches over cumulative probabilities per generated nucleotide, cumulative distribution thresholds are precomputed into a 136.7 KB direct lookup array (char lookup[IM]). Each pseudo-random integer in $[0, IM)$ immediately indexes the corresponding nucleotide in $O(1)$ with zero floating-point arithmetic or branch mispredictions in the hot loop.
  • High-Throughput Block Buffered Output: Employs a 256 KB contiguous output buffer (out_buf) with batched fwrite, minimizing system-call overhead while remaining fully compliant with standard single-threaded output constraints.
  • Double-Buffer ALU Sequence: Concatenates sequence prefix to avoid modulo arithmetic during repeated wrap operations.

Verification

  • Bit-exact verification against bench/algorithm/fasta/1000_out ($N = 1000$).
  • Bit-exact verification against Rust 1.rs canonical reference across 25,000 iterations ($N = 25000$).
  • Clean compilation under GCC / Clang with -pipe -Wall -Wextra -O3 -fomit-frame-pointer -std=c++20.

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