parse_number() 作为 SQLite 扩展:C 与 Rust 对比
原标题:parse_number() as a SQLite extension: C vs Rust
AI 摘要
Simon Willison 在遛狗时产生想法,用 Claude Opus 5.5 探索为 SQLite 编写 parse_number() 自定义函数,比较 C 与 Rust 扩展在性能、代码复杂度和产物大小上的差异。初步结果显示 Rust 扩展(321KB/298KB)远大于 C 扩展(14KB),但 Rust 版本更快,原因是其 strtod 等价实现速度约为 C 的两倍。随后他让 Claude 手写 C 解析函数,新 C 实现在混合数据、纯整数、纯小数场景下均反超 Rust 实现。最后他将调查整理为 simonw/research 仓库中的研究报告。
正文节选
8th November 2026 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