November 8, 2026
Research parse_number() as an SQLite extension: C vs. Rust—Four SQLite extensions implement the same parse_number() behavior in C and Rust, with tests covering type preservation, parsing rules, and floating-point precision. The optimized C implementation is the fastest at 16–19 nanoseconds (ns) per row—roughly twice as fast as the Rust versions and far faster than SQL’s replace(). The original C implementation was slower on decimals because it relied on strtod(), but a compact fast path closed this gap; all versions agree across 8 million fuzz checks.
While out walking the dog, I got curious about how hard or easy it would be to write a C extension for SQLite that adds a parse_number() function to convert strings like -$1,234.56 or '12.5%' into numbers suitable for summing and sorting.
I opened my usual Claude chat (Opus 5.5) and prompted it:
I want to make an SQLite custom function 'parse_number(value)' that strips out ',', '$', '£', and '%', handles a leading '-', and returns 'NULL' for anything that can't be parsed
Talk through the differences between building this as an SQLite extension in C vs Rust - I want to compare performance, code complexity and size of the resulting .so (or whatever)
This gave me a solid starting point—the Rust extensions were 321 KB (using Rusqlite) and 298 KB (using sqlite-loadable-rs), compared to just 14 KB for the C extension. However, the Rust extensions ran faster!
It turned out this was because Rust’s equivalent of C’s strtod was “twice as fast.” So I prompted it again:
Try writing your own C text-to-decimal function to catch up with or beat the Rust implementation
It did indeed:
Net overhead per row for 2,000,000 rows (lower is better):
Initial C New C rusqlite sqlite-loadable Mixed data 67 ns 19 ns 46 ns 41 ns Integers only 25 ns 16 ns 36 ns 32 ns Decimals only 106 ns 18 ns 55 ns 47 ns
Finally, I prompted it to turn the prototype into a research report that matched the style of the other reports in simonw/research:
Clone simonw/research from GitHub and turn your investigation above into a research report that matches the style in that repo - you can provide a zip file of a new folder for me to download
Here is the final research report.