A new benchmark result demonstrates that pure functional programming languages can get surprisingly close to C’s runtime performance. According to a detailed analysis on rtfeldman.com, a DEFLATE compression library written in Roc, a functional programming language focused on runtime performance, achieved median slowdown of only 8.9% compared to libdeflate, a heavily optimized C implementation.

The roc-deflate package, originally written by Niclas Ahden, was subjected to extensive performance optimization work. Testing on the Silesia corpus benchmark suite across two different machines—an M1 MacBook Pro and an AMD Ryzen 9 3900X—showed consistent results. On the MacBook Pro, the gap was even smaller at 2.6% slower on median cases.
The comparison is particularly notable given the constraints Roc operates under. Unlike libdeflate, which uses architecture-specific SIMD instructions and can skip bounds checks, Roc is a functional language with automatic memory management, bounds checking, and no unsafe code options. Despite these safety features, the performance gap remained in single digits on median inputs, though worst-case scenarios showed roc-deflate running 18% slower. Interestingly, on some inputs roc-deflate actually outperformed libdeflate by over 18%.
According to the analysis, this result demonstrates what was previously unknown to be achievable. However, the author notes that C’s performance ceiling remains higher than Roc’s—C implementations can theoretically close any performance gap where Roc happens to be faster, but not vice versa.
Beyond raw performance numbers, the pure functional implementation offers several advantages over C code. Roc enforces complete memory safety with no opt-out mechanisms, guaranteed absence of side effects through its type system, and protection against supply-chain attacks by disallowing arbitrary foreign function interfaces and build scripts. The implementation also provides deterministic behavior across different target platforms.
The author acknowledges this is a single optimization case and cautions against generalizing results broadly. Roc remains a nascent language still weeks away from its first numbered release, with minimal optimization work done on most packages. How well other Roc codebases can approach this performance level remains an open question.
Key facts
- Roc’s roc-deflate library ran 8.9% slower than libdeflate on median benchmarks across an AMD Ryzen processor
- On an M1 MacBook Pro, the median gap was only 2.6%
- Worst-case performance showed 18% slowdown, but best-case inputs ran over 18% faster than libdeflate
- Roc enforces memory safety, pure functions, and prevents supply-chain attacks through design constraints
- This represents the most optimization effort applied to any Roc package to date
