hiw3c 日报精选
Simon Willison 网页快照

parse_number()作为SQLite扩展:C与Rust

原文标题 · parse_number() as a SQLite extension: C vs Rust

研究:parse_number()作为SQLite扩展:C与Rust 我在遛狗时对编写一个SQLite C扩展的难度/容易度感到好奇,该扩展将添加一个parse_number()函数,用于将如“-$1,234.56”或“12.5%”这样的字符串转换为可求和和排序的数值。我启动了常规Claude聊天工具(Opus 5.5),并提问:我在考虑一个SQLite自定义函数“parse_number(val

来源:Simon Willison · simonwillison.net

正文为英文,可一键机器翻译(仅首次需要等待)

Simon Willison’s Weblog

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

Recent articles

Hide your slop PR descriptions behind <details><summary> - 9th November 2026

Qwen 3.8 27B on my laptop can interpret model weights, too - 3rd November 2026

The U.S. Census Bureau and “Super Intelligence” - 2nd November 2026

The October inflection point for vibe game development - 28th October 2026

This is a beat by Simon Willison, posted on 8th November 2026 .

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.