From d74aaf33093011b565d31a193678d881ba17b7ff Mon Sep 17 00:00:00 2001 From: Tim Fennis Date: Tue, 8 Sep 2026 15:51:41 +0200 Subject: [PATCH] =?UTF-8?q?test(bench):=20benchmark=20indexing=20in=20long?= =?UTF-8?q?=20strings=20=F0=9F=A7=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benches/programs/string_index_ascii.ndc | 15 +++++++++++++++ benches/programs/string_index_unicode.ndc | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 benches/programs/string_index_ascii.ndc create mode 100644 benches/programs/string_index_unicode.ndc diff --git a/benches/programs/string_index_ascii.ndc b/benches/programs/string_index_ascii.ndc new file mode 100644 index 00000000..ee75638a --- /dev/null +++ b/benches/programs/string_index_ascii.ndc @@ -0,0 +1,15 @@ +// 10,000 reads near the end of a 131,072-codepoint ASCII string. +// Build by doubling so construction is small compared with O(n) indexing. +let text = "abcd"; +for _ in 0..15 { + text <>= text; +} +let last = text.len - 1; +let matches = 0; +for i in 0..10_000 { + if text[last - i % 4] == "d" { + matches += 1; + } +} +assert_eq(matches, 2_500); +print(matches); diff --git a/benches/programs/string_index_unicode.ndc b/benches/programs/string_index_unicode.ndc new file mode 100644 index 00000000..eb4e4c59 --- /dev/null +++ b/benches/programs/string_index_unicode.ndc @@ -0,0 +1,15 @@ +// Same codepoint count and access pattern as string_index_ascii.ndc, +// with a mix of 1-, 2-, 3-, and 4-byte UTF-8 codepoints. +let text = "aé中😀"; +for _ in 0..15 { + text <>= text; +} +let last = text.len - 1; +let matches = 0; +for i in 0..10_000 { + if text[last - i % 4] == "😀" { + matches += 1; + } +} +assert_eq(matches, 2_500); +print(matches);