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);