mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
The fast path is now 4.4x faster, now making it ~2.6x times
faster than `CGI.escape_html`, and 26x faster than an equivalent
`gsub`.
```
compare-ruby: ruby 4.1.0dev (2026-09-06T11:22:48Z master 13fc4ffd32) +YJIT +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-09-06T14:39:43Z string-tr-simd e2526ca9ba) +YJIT +PRISM [arm64-darwin25]
``
| |compare-ruby|built-ruby|
|:------------|-----------:|---------:|
|tr_escape | 41.595k| 182.732k|
| | -| 4.39x|
|gsub_escape | 7.135k| 6.977k|
| | 1.02x| -|
|cgi_escape | 70.117k| 70.179k|
| | -| 1.00x|
However, contrary to a lookup table, here the performance is linear with
the number of characters to match, hence once we're looking for 16 distinct
bytes, the gain compared to the lookup table is down to ~2x.
19 lines
481 B
C
19 lines
481 B
C
#ifndef INTERNAL_SIMD_H
|
|
#define INTERNAL_SIMD_H
|
|
|
|
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
|
|
#ifdef HAVE_X86INTRIN_H
|
|
#include <x86intrin.h>
|
|
#define HAVE_SIMD 1
|
|
#define HAVE_SIMD_SSE2 1
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(__aarch64__) || defined(_M_ARM64)
|
|
#define HAVE_SIMD 1
|
|
#define HAVE_SIMD_NEON 1
|
|
#include <arm_neon.h>
|
|
#endif
|
|
|
|
#endif /* INTERNAL_SIMD_H */
|