unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

punycode/punycode_bench_test.mbt
1///|2/// Keep input preparation outside the timed closures. Run with:3/// moon bench punycode --target native --release4/// (also --target wasm and --target wasm-gc).5test "encode and decode" (b : @bench.T) {6  for7    (name, input) in [8      ("ASCII", "example"),9      ("Latin", "bücher"),10      ("Arabic", "مثال"),11      ("CJK", "日本語テスト例え"),12      ("supplementary", "😀😃😄𝒜"),13      (14        "long", "ünïcödé-ünïcödé-ünïcödé-ünïcödé-ünïcödé-ünïcödé",15      ),16    ] {17    // Every input round-trips, so the closures time successful calls only.18    let encoded = @punycode.encode(input)19    assert_eq(@punycode.decode(encoded), input)20    b.bench(name="encode/\{name}", fn() {21      b.keep(@punycode.encode(input) catch { _ => input })22    })23    b.bench(name="decode/\{name}", fn() {24      b.keep(@punycode.decode(encoded) catch { _ => encoded })25    })26  }27}28