parse_number
A custom SQLite scalar function that parses strings containing currency symbols, thousands separators, and percent signs into numeric values, facilitating summation and sorting within a database. It serves as an example for comparing the size and performance of SQLite extensions implemented in C and in Rust.
Timeline (last 90 days)
Simon Willison used Claude (Opus 5.5) to implement SQLite's parse_number() extension in C and in Rust respectively, and conducted a performance comparison experiment.
In a test with 2 million rows, the per-row net overhead of the new C implementation was: 19 ns for mixed data, 16 ns for pure integers, and 18 ns for pure decimals; the first C implementation was 67 ns, 25 ns, and 106 ns respectively; the rusqlite version was 46 ns, 36 ns, and 55 ns respectively; the sqlite-loadable version was 41 ns, 32 ns, and 47 ns respectively.
The custom C parser reduced decimal parsing from 106 ns to 18 ns, because the input domain of parse_number was narrowed (it only needs to strip currency symbols, thousands separators, and percent signs), allowing it to skip the branching and validation overhead that strtod pays for generality.
All Facts (3)
In a test with 2 million rows, the per-row net overhead of the new C implementation was: 19 ns for mixed data, 16 ns for pure integers, and 18 ns for pure decimals; the first C implementation was 67 ns, 25 ns, and 106 ns respectively; the rusqlite version was 46 ns, 36 ns, and 55 ns respectively; the sqlite-loadable version was 41 ns, 32 ns, and 47 ns respectively.
50%UnverifiedThe custom C parser reduced decimal parsing from 106 ns to 18 ns, because the input domain of parse_number was narrowed (it only needs to strip currency symbols, thousands separators, and percent signs), allowing it to skip the branching and validation overhead that strtod pays for generality.
50%UnverifiedSimon Willison used Claude (Opus 5.5) to implement SQLite's parse_number() extension in C and in Rust respectively, and conducted a performance comparison experiment.
50%