normalization/normalization_bench_test.mbt1///|2/// Keep input construction outside the timed closures. Run with:3/// moon bench normalization --target native --release4/// (also --target wasm and --target wasm-gc).5test "normalization spans" (b : @bench.T) {6 for7 (name, input) in [8 ("changed prefix ASCII tail", "e\u{0301}" + "Hello world! ".repeat(256)),9 ("Maybe prefix ASCII tail", "x\u{0301}" + "Hello world! ".repeat(256)),10 (11 "separated changes",12 ("e\u{0301}" + "Hello world! ".repeat(64)).repeat(4),13 ),14 ("ASCII", "Hello world! ".repeat(256)),15 // Per-call overhead dominates: one short clean run, then the end.16 ("short ASCII", "Hello"),17 ("short BMP", "世界"),18 ("short accented Latin", "Café"),19 ("BMP starters", "中文日本語".repeat(256)),20 ("supplementary starters", "😀𠀀𝄞".repeat(256)),21 ("default supplementary tail", "\u{10FFFD}".repeat(256)),22 ("normalized mixed", "Café 世界 😀 한글 ".repeat(128)),23 ("decomposed mixed", "Cafe\u{0301} 世界 😀 한글 ".repeat(128)),24 ("dense composition", "e\u{0301}".repeat(256)),25 ("dense unchanged Maybe", "x\u{0301}".repeat(256)),26 ("NFC compatibility characters", "ffiA\u{030A}".repeat(256)),27 ("Hangul Jamo", "각".repeat(256)),28 ("long combining run", "a" + "\u{0315}\u{0300}".repeat(64)),29 ] {30 b.bench(name="NFC/\{name}", fn() { b.keep(@normalization.nfc(input)) })31 b.bench(name="is_normalized/\{name}", fn() {32 b.keep(@normalization.is_normalized(input, @normalization.NFC))33 })34 }35}3637///|38// Exercise supplementary lookups after the BMP path becomes hot in the same VM.39test "supplementary after BMP warmup" (b : @bench.T) {40 let bmp = "中文日本語".repeat(256)41 for _ in 0..<2000 {42 b.keep(@normalization.nfc(bmp))43 }44 let input = "😀𠀀𝄞".repeat(4096)45 b.bench(name="NFC/supplementary after BMP warmup", fn() {46 b.keep(@normalization.nfc(input))47 })48}4950///|51test "supplementary clean and suspect groups" (b : @bench.T) {52 for53 (name, input) in [54 ("default tail in active group", "\u{2FA80}".repeat(256)),55 ("inert surrogate group", "😀".repeat(256)),56 ("active surrogate group", "\u{1D400}".repeat(256)),57 ("changed prefix default tail", "e\u{0301}" + "\u{10FFFD}".repeat(256)),58 (59 "default tail between changes",60 "e\u{0301}" + "\u{10FFFD}".repeat(256) + "A\u{030A}",61 ),62 ] {63 for64 form in [65 @normalization.NFC,66 @normalization.NFD,67 @normalization.NFKC,68 @normalization.NFKD,69 ] {70 b.bench(name="\{form}/\{name}/normalize", fn() {71 b.keep(@normalization.normalize(input, form))72 })73 b.bench(name="\{form}/\{name}/check", fn() {74 b.keep(@normalization.is_normalized(input, form))75 })76 }77 }78}79
///|
/// Keep input construction outside the timed closures. Run with:
/// moon bench normalization --target native --release
/// (also --target wasm and --target wasm-gc).
test "normalization spans" (b : @bench.T) {
for
(name, input) in [
("changed prefix ASCII tail", "e\u{0301}" + "Hello world! ".repeat(256)),
("Maybe prefix ASCII tail", "x\u{0301}" + "Hello world! ".repeat(256)),
(
"separated changes",
("e\u{0301}" + "Hello world! ".repeat(64)).repeat(4),
),
("ASCII", "Hello world! ".repeat(256)),
// Per-call overhead dominates: one short clean run, then the end.
("short ASCII", "Hello"),
("short BMP", "世界"),
("short accented Latin", "Café"),
("BMP starters", "中文日本語".repeat(256)),
("supplementary starters", "😀𠀀𝄞".repeat(256)),
("default supplementary tail", "\u{10FFFD}".repeat(256)),
("normalized mixed", "Café 世界 😀 한글 ".repeat(128)),
("decomposed mixed", "Cafe\u{0301} 世界 😀 한글 ".repeat(128)),
("dense composition", "e\u{0301}".repeat(256)),
("dense unchanged Maybe", "x\u{0301}".repeat(256)),
("NFC compatibility characters", "ffiA\u{030A}".repeat(256)),
("Hangul Jamo", "각".repeat(256)),
("long combining run", "a" + "\u{0315}\u{0300}".repeat(64)),
] {
b.bench(name="NFC/\{name}", fn() { b.keep(@normalization.nfc(input)) })
b.bench(name="is_normalized/\{name}", fn() {
b.keep(@normalization.is_normalized(input, @normalization.NFC))
})
}
}
///|
// Exercise supplementary lookups after the BMP path becomes hot in the same VM.
test "supplementary after BMP warmup" (b : @bench.T) {
let bmp = "中文日本語".repeat(256)
for _ in 0..<2000 {
b.keep(@normalization.nfc(bmp))
}
let input = "😀𠀀𝄞".repeat(4096)
b.bench(name="NFC/supplementary after BMP warmup", fn() {
b.keep(@normalization.nfc(input))
})
}
///|
test "supplementary clean and suspect groups" (b : @bench.T) {
for
(name, input) in [
("default tail in active group", "\u{2FA80}".repeat(256)),
("inert surrogate group", "😀".repeat(256)),
("active surrogate group", "\u{1D400}".repeat(256)),
("changed prefix default tail", "e\u{0301}" + "\u{10FFFD}".repeat(256)),
(
"default tail between changes",
"e\u{0301}" + "\u{10FFFD}".repeat(256) + "A\u{030A}",
),
] {
for
form in [
@normalization.NFC,
@normalization.NFD,
@normalization.NFKC,
@normalization.NFKD,
] {
b.bench(name="\{form}/\{name}/normalize", fn() {
b.keep(@normalization.normalize(input, form))
})
b.bench(name="\{form}/\{name}/check", fn() {
b.keep(@normalization.is_normalized(input, form))
})
}
}
}