← All IntelIntel / article
parse_number() as a SQLite extension: C vs Rust
- Source
- simonwillison.net
- Date
Why it matters
Gives measured numbers: optimized C ran 16 to 19 ns per row, about twice as fast as Rust, with a 14 KB binary versus roughly 300 KB. It also shows an -driven workflow backed by fuzz-testing.
Key takeaways · AI-distilled
- Willison's parse_number() strips commas, $, £ and % from strings like -$1,234.56 or '12.5%', keeps a leading minus, and returns NULL for anything it cannot parse, so formatted text can be summed and sorted as numbers inside SQLite.
- The first C build lost to Rust because it called strtod(): on decimal-only data it cost 106 ns per row versus 47 to 55 ns for the two Rust builds. Willison reports that Rust's equivalent of strtod is about twice as fast.
- A second prompt asking Claude to write its own C decimal parser cut decimal-only parsing from 106 ns to 18 ns per row over 2 million rows, flipping the result so C beat both Rust builds on every data mix tested.
- The two Rust builds used different bindings, Rusqlite (321 KB) and sqlite-loadable-rs (298 KB), and the sqlite-loadable build was slightly faster on every mix in Willison's table, for example 41 ns versus 46 ns per row on mixed data.
Terms in this piece · Glossary
Read the source simonwillison.net
Recommended reads
Comments
Checking sign-in…
Loading comments…
