StringZilla

StringZilla

跨平台高性能字符串操作加速库

StringZilla是一款利用SIMD和SWAR技术优化字符串操作的跨平台库。相比传统库和其他SIMD加速库,它在C、C++、Python等语言中实现了高达10倍的性能提升。StringZilla支持精确和模糊字符串匹配、编辑距离计算、排序、惰性评估等功能,还提供随机字符串生成器。这一工具适用于处理大规模数据集的工程师、需要优化字符串操作的开发人员,以及各类对字符串处理性能有较高要求的项目。

StringZilla字符串处理性能优化SIMD多语言支持Github开源项目

StringZilla 🦖

StringZilla banner

The world wastes a minimum of $100M annually due to inefficient string operations. A typical codebase processes strings character by character, resulting in too many branches and data-dependencies, neglecting 90% of modern CPU's potential. LibC is different. It attempts to leverage SIMD instructions to boost some operations, and is often used by higher-level languages, runtimes, and databases. But it isn't perfect. 1️⃣ First, even on common hardware, including over a billion 64-bit ARM CPUs, common functions like strstr and memmem only achieve 1/3 of the CPU's throughput. 2️⃣ Second, SIMD coverage is inconsistent: acceleration in forward scans does not guarantee speed in the reverse-order search. 3️⃣ At last, most high-level languages can't always use LibC, as the strings are often not NULL-terminated or may contain the Unicode "Zero" character in the middle of the string. That's why StringZilla was created. To provide predictably high performance, portable to any modern platform, operating system, and programming language.

StringZilla Python installs StringZilla Rust installs GitHub Actions Workflow Status GitHub Actions Workflow Status GitHub Actions Workflow Status GitHub Actions Workflow Status StringZilla code size

StringZilla is the GodZilla of string libraries, using SIMD and SWAR to accelerate string operations on modern CPUs. It is up to 10x faster than the default and even other SIMD-accelerated string libraries in C, C++, Python, and other languages, while covering broad functionality. It accelerates exact and fuzzy string matching, edit distance computations, sorting, lazily-evaluated ranges to avoid memory allocations, and even random-string generators.

  • 🐂 C : Upgrade LibC's <string.h> to <stringzilla.h> in C 99
  • 🐉 C++: Upgrade STL's <string> to <stringzilla.hpp> in C++ 11
  • 🐍 Python: Upgrade your str to faster Str
  • 🍎 Swift: Use the String+StringZilla extension
  • 🦀 Rust: Use the StringZilla traits crate
  • 🐚 Shell: Accelerate common CLI tools with sz_ prefix
  • 📚 Researcher? Jump to Algorithms & Design Decisions
  • 💡 Thinking to contribute? Look for "good first issues"
  • 🤝 And check the guide to setup the environment
  • Want more bindings or features? Let me know!

Who is this for?

  • For data-engineers parsing large datasets, like the CommonCrawl, RedPajama, or LAION.
  • For software engineers optimizing strings in their apps and services.
  • For bioinformaticians and search engineers looking for edit-distances for USearch.
  • For DBMS devs, optimizing LIKE, ORDER BY, and GROUP BY operations.
  • For hardware designers, needing a SWAR baseline for strings-processing functionality.
  • For students studying SIMD/SWAR applications to non-data-parallel operations.

Performance

<table style="width: 100%; text-align: center; table-layout: fixed;"> <colgroup> <col style="width: 25%;"> <col style="width: 25%;"> <col style="width: 25%;"> <col style="width: 25%;"> </colgroup> <tr> <th align="center">C</th> <th align="center">C++</th> <th align="center">Python</th> <th align="center">StringZilla</th> </tr> <!-- Substrings, normal order --> <tr> <td colspan="4" align="center">find the first occurrence of a random word from text, ≅ 5 bytes long</td> </tr> <tr> <td align="center"> <code>strstr</code> <sup>1</sup><br/> <span style="color:#ABABAB;">x86:</span> <b>7.4</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>2.0</b> GB/s </td> <td align="center"> <code>.find</code><br/> <span style="color:#ABABAB;">x86:</span> <b>2.9</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>1.6</b> GB/s </td> <td align="center"> <code>.find</code><br/> <span style="color:#ABABAB;">x86:</span> <b>1.1</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.6</b> GB/s </td> <td align="center"> <code>sz_find</code><br/> <span style="color:#ABABAB;">x86:</span> <b>10.6</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>7.1</b> GB/s </td> </tr> <!-- Substrings, reverse order --> <tr> <td colspan="4" align="center">find the last occurrence of a random word from text, ≅ 5 bytes long</td> </tr> <tr> <td align="center">⚪</td> <td align="center"> <code>.rfind</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.5</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.4</b> GB/s </td> <td align="center"> <code>.rfind</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.9</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.5</b> GB/s </td> <td align="center"> <code>sz_rfind</code><br/> <span style="color:#ABABAB;">x86:</span> <b>10.8</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>6.7</b> GB/s </td> </tr> <!-- Characters, normal order --> <tr> <td colspan="4" align="center">split lines separated by <code>\n</code> or <code>\r</code> <sup>2</sup></td> </tr> <tr> <td align="center"> <code>strcspn</code> <sup>1</sup><br/> <span style="color:#ABABAB;">x86:</span> <b>5.42</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>2.19</b> GB/s </td> <td align="center"> <code>.find_first_of</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.59</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.46</b> GB/s </td> <td align="center"> <code>re.finditer</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.06</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.02</b> GB/s </td> <td align="center"> <code>sz_find_charset</code><br/> <span style="color:#ABABAB;">x86:</span> <b>4.08</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>3.22</b> GB/s </td> </tr> <!-- Characters, reverse order --> <tr> <td colspan="4" align="center">find the last occurrence of any of 6 whitespaces <sup>2</sup></td> </tr> <tr> <td align="center">⚪</td> <td align="center"> <code>.find_last_of</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.25</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.25</b> GB/s </td> <td align="center">⚪</td> <td align="center"> <code>sz_rfind_charset</code><br/> <span style="color:#ABABAB;">x86:</span> <b>0.43</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>0.23</b> GB/s </td> </tr> <!-- Random Generation --> <tr> <td colspan="4" align="center">Random string from a given alphabet, 20 bytes long <sup>5</sup></td> </tr> <tr> <td align="center"> <code>rand() % n</code><br/> <span style="color:#ABABAB;">x86:</span> <b>18.0</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>9.4</b> MB/s </td> <td align="center"> <code>uniform_int_distribution</code><br/> <span style="color:#ABABAB;">x86:</span> <b>47.2</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>20.4</b> MB/s </td> <td align="center"> <code>join(random.choices(...))</code><br/> <span style="color:#ABABAB;">x86:</span> <b>13.3</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>5.9</b> MB/s </td> <td align="center"> <code>sz_generate</code><br/> <span style="color:#ABABAB;">x86:</span> <b>56.2</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>25.8</b> MB/s </td> </tr> <!-- Sorting --> <tr> <td colspan="4" align="center">Get sorted order, ≅ 8 million English words <sup>6</sup></td> </tr> <tr> <td align="center"> <code>qsort_r</code><br/> <span style="color:#ABABAB;">x86:</span> <b>3.55</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>5.77</b> s </td> <td align="center"> <code>std::sort</code><br/> <span style="color:#ABABAB;">x86:</span> <b>2.79</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>4.02</b> s </td> <td align="center"> <code>numpy.argsort</code><br/> <span style="color:#ABABAB;">x86:</span> <b>7.58</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>13.00</b> s </td> <td align="center"> <code>sz_sort</code><br/> <span style="color:#ABABAB;">x86:</span> <b>1.91</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>2.37</b> s </td> </tr> <!-- Edit Distance --> <tr> <td colspan="4" align="center">Levenshtein edit distance, ≅ 5 bytes long</td> </tr> <tr> <td align="center">⚪</td> <td align="center">⚪</td> <td align="center"> via <code>jellyfish</code> <sup>3</sup><br/> <span style="color:#ABABAB;">x86:</span> <b>1,550</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>2,220</b> ns </td> <td align="center"> <code>sz_edit_distance</code><br/> <span style="color:#ABABAB;">x86:</span> <b>99</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>180</b> ns </td> </tr> <!-- Alignment Score --> <tr> <td colspan="4" align="center">Needleman-Wunsch alignment scores, ≅ 10 K aminoacids long</td> </tr> <tr> <td align="center">⚪</td> <td align="center">⚪</td> <td align="center"> via <code>biopython</code> <sup>4</sup><br/> <span style="color:#ABABAB;">x86:</span> <b>257</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>367</b> ms </td> <td align="center"> <code>sz_alignment_score</code><br/> <span style="color:#ABABAB;">x86:</span> <b>73</b> &centerdot; <span style="color:#ABABAB;">arm:</span> <b>177</b> ms </td> </tr> </table>

StringZilla has a lot of functionality, most of which is covered by benchmarks across C, C++, Python and other languages. You can find those in the ./scripts directory, with usage notes listed in the CONTRIBUTING.md file. Notably, if the CPU supports misaligned loads, even the 64-bit SWAR backends are faster than either standard library.

Most benchmarks were

编辑推荐精选

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成AI工具AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

下拉加载更多