idna/idna2008_bench_test.mbt1///|2/// Benchmark the public conversion pipeline with both optional IDNA20083/// checks enabled. Inputs and their A-label forms are validated before timing.4/// Run with moon bench idna/idna2008_bench_test.mbt --target native --release5/// (also --target js, --target wasm-gc, and --target wasm).6test "IDNA2008 domain conversion" (b : @bench.T) {7 for8 (name, input) in [9 ("ASCII", "www.example.com"),10 ("Latin", "bücher.münchen.example"),11 ("middle dot", "l·l.example"),12 ("Greek", "\u{0375}α.example"),13 ("Hebrew", "א\u{05F3}.example"),14 ("Japanese early", "カ・abcdefghijklmnopqrstuvwx.example"),15 ("Japanese late", "abcdefghijklmnopqrstuvwx・カ.example"),16 ("Arabic digits", "ا١٢٣٤٥٦٧٨٩٠.example"),17 (18 "long middle dots", "l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l.example",19 ),20 ] {21 let ascii = @idna.to_ascii(input, check_idna2008=true, check_contexto=true)22 ignore(@idna.to_unicode(ascii, check_idna2008=true, check_contexto=true))23 b.bench(name="to_ascii/\{name}", fn() {24 b.keep(25 @idna.to_ascii(input, check_idna2008=true, check_contexto=true) catch {26 _ => input27 },28 )29 })30 b.bench(name="to_unicode/\{name}", fn() {31 b.keep(32 @idna.to_unicode(ascii, check_idna2008=true, check_contexto=true) catch {33 _ => ascii34 },35 )36 })37 }38}39
///|
/// Benchmark the public conversion pipeline with both optional IDNA2008
/// checks enabled. Inputs and their A-label forms are validated before timing.
/// Run with moon bench idna/idna2008_bench_test.mbt --target native --release
/// (also --target js, --target wasm-gc, and --target wasm).
test "IDNA2008 domain conversion" (b : @bench.T) {
for
(name, input) in [
("ASCII", "www.example.com"),
("Latin", "bücher.münchen.example"),
("middle dot", "l·l.example"),
("Greek", "\u{0375}α.example"),
("Hebrew", "א\u{05F3}.example"),
("Japanese early", "カ・abcdefghijklmnopqrstuvwx.example"),
("Japanese late", "abcdefghijklmnopqrstuvwx・カ.example"),
("Arabic digits", "ا١٢٣٤٥٦٧٨٩٠.example"),
(
"long middle dots", "l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l·l.example",
),
] {
let ascii = @idna.to_ascii(input, check_idna2008=true, check_contexto=true)
ignore(@idna.to_unicode(ascii, check_idna2008=true, check_contexto=true))
b.bench(name="to_ascii/\{name}", fn() {
b.keep(
@idna.to_ascii(input, check_idna2008=true, check_contexto=true) catch {
_ => input
},
)
})
b.bench(name="to_unicode/\{name}", fn() {
b.keep(
@idna.to_unicode(ascii, check_idna2008=true, check_contexto=true) catch {
_ => ascii
},
)
})
}
}