Urgent.News

What's breaking now, across thousands of outlets.

Culture

parse_number() as a SQLite extension: C vs Rust

Research: parse_number() as a SQLite extension: C vs Rust I was out walking the dog when I got curious about how easy/difficult it would be to write a SQLite C extension that adds a parse_number() function for turning strings like -$1,234.56 or '12.5%' into numeric values that could be summed and sorted. I fired up regular Claude chat (Opus 5.5) and prompted : I'm thinking about a SQLite custom…

A reporter set out to investigate the ease of creating a SQLite extension that includes a function for parsing strings into numeric values, such as -$1,234.56 or 12.5%. The reporter used Claude chat (Opus 5.5) to prompt the idea of a custom function named parse_number(value) that would strip out characters like commas, currency symbols, and percentages, as well as handle negative signs.

The reporter was curious to compare the performance of building this extension in C versus Rust, as well as the complexity and size of the resulting .so file.

The results showed that the Rust implementation was significantly faster, with the Rust extension being 321 KB (using Rusqlite) and 298 KB (using sqlite-loadable-rs), while the C extension was only 14 KB. This performance difference was attributed to the Rust equivalent of C's strtod being twice as fast. The reporter then proceeded to write their own C function to see if it could match or surpass the Rust implementation when parsing text into decimal numbers.

The net cost per row when processing 2 million rows was compared, with the lower cost being preferred. Finally, the reporter aimed to turn their investigation into a research report, following the format used in the simonw/research repository.

Written by urgent.news from Simon Willison's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at simonwillison.net →

More in Culture

More from Sunday 8 November →