unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

normalization/normalization_bench_test.mbt
1///|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