ucd/case_mapping_bench_test.mbt1///|2/// Keep input construction outside the timed closures. Run with:3/// moon bench ucd --target native --release4/// (also --target wasm and --target wasm-gc).5test "case mapping" (b : @bench.T) {6 for7 (name, input) in [8 ("ASCII", "Hello world, this is a Test. ".repeat(32)),9 ("Latin", "Ünïcödé Çàfé Straße ".repeat(32)),10 ("Greek", "Ὀδυσσεύς καὶ ᾈχιλλεύς ".repeat(32)),11 ("CJK", "世界こんにちは、テスト。".repeat(64)),12 ] {13 b.bench(name="to_simple_uppercase/\{name}", fn() {14 let mut sum = 015 for c in input {16 sum = sum ^ @ucd.to_simple_uppercase(c).to_int()17 }18 b.keep(sum)19 })20 b.bench(name="to_simple_lowercase/\{name}", fn() {21 let mut sum = 022 for c in input {23 sum = sum ^ @ucd.to_simple_lowercase(c).to_int()24 }25 b.keep(sum)26 })27 b.bench(name="to_uppercase/\{name}", fn() {28 let mut length = 029 for c in input {30 length += @ucd.to_uppercase(c).length()31 }32 b.keep(length)33 })34 b.bench(name="to_lowercase/\{name}", fn() {35 let mut length = 036 for c in input {37 length += @ucd.to_lowercase(c).length()38 }39 b.keep(length)40 })41 }42}43
///|
/// Keep input construction outside the timed closures. Run with:
/// moon bench ucd --target native --release
/// (also --target wasm and --target wasm-gc).
test "case mapping" (b : @bench.T) {
for
(name, input) in [
("ASCII", "Hello world, this is a Test. ".repeat(32)),
("Latin", "Ünïcödé Çàfé Straße ".repeat(32)),
("Greek", "Ὀδυσσεύς καὶ ᾈχιλλεύς ".repeat(32)),
("CJK", "世界こんにちは、テスト。".repeat(64)),
] {
b.bench(name="to_simple_uppercase/\{name}", fn() {
let mut sum = 0
for c in input {
sum = sum ^ @ucd.to_simple_uppercase(c).to_int()
}
b.keep(sum)
})
b.bench(name="to_simple_lowercase/\{name}", fn() {
let mut sum = 0
for c in input {
sum = sum ^ @ucd.to_simple_lowercase(c).to_int()
}
b.keep(sum)
})
b.bench(name="to_uppercase/\{name}", fn() {
let mut length = 0
for c in input {
length += @ucd.to_uppercase(c).length()
}
b.keep(length)
})
b.bench(name="to_lowercase/\{name}", fn() {
let mut length = 0
for c in input {
length += @ucd.to_lowercase(c).length()
}
b.keep(length)
})
}
}