parse_number() as a SQLite extension: C vs Rust

星海拾光AI 前沿📡 Simon Willison's Weblog2026-11-09551 阅读💛 270 收藏

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 function 'parse_number(value)' that strips ',', '

, '£' and '%', handles a leading '-', and returns 'NULL' for anything it can’t parse

Explore the difference between building this as a SQLite extension in C v.s. in Rust - I want to compare performance and code complexity and size of the resulting .so (or whatever) file

This gave me a solid starting point - the Rust extension was 321 KB (using Rusqlite ) and 298 KB (using sqlite-loadable-rs ), while the C extension was 14 KB. But the Rust extension was faster!

Turns out that's because the Rust equivalent of C's strtod is "twice as fast". So I prompted:

Try writing your own C function for parsing text into a decimal number that catches up to or beats the Rust implementation

And it did, using "Clinger's fast path":

Net cost per row over 2 million rows, lower is better:

first 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 had it rewrite the prototype as a research report to match the others in simonw/research by prompting this:

Clone simonw/research from GitHub and turn your above investigation into a research report as seen in that repository - you can give me a zip file to download that contains your new folder

Here's the resulting report .

Tags: c , research , sqlite , rust , claude

文章评论(12)

山问津6 天前

看完了,收获满满,期待更多更新。

回复
陈皮话梅糖6 天前

很有价值的分享,感谢整理。

回复
山问津6 天前

刚好最近在找这方面的资料,太及时了。

回复
星知秋6 天前

这个比较实用,已转发给同事。

回复
拾贝者6 天前

支持作者,持续关注中。

回复
星寻梦6 天前

很有价值的分享,感谢整理。

回复
墨沐雨6 天前

刚好最近在找这方面的资料,太及时了。

回复
郭超6 天前

路过

回复
风倚栏6 天前

看完了,收获满满,期待更多更新。

回复
月沐雨6 天前

不错不错,已加入书签。

回复
蓝问津6 天前

看标题就点进来了,内容果然没让人失望。

回复
蓝归舟6 天前

作者写得真不错,学到了不少。

回复
← 返回文章列表
{{WIDGETS_FULL}}