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

编辑推荐精选

Keevx

Keevx

AI数字人视频创作平台

Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。

即梦AI

即梦AI

一站式AI创作平台

提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作

扣子-AI办公

扣子-AI办公

AI办公助手,复杂任务高效处理

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

TRAE编程

TRAE编程

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

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

AI工具TraeAI IDE协作生产力转型热门
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI辅助写作AI工具蛙蛙写作AI写作工具学术助手办公助手营销助手AI助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

下拉加载更多