unicode
Punctuation benchmark
Compare the dedicated punctuation predicate with the General_Category group lookup:
@unicode.is_punctuation(c)
@unicode.general_category(c).group() is @unicode.GeneralCategoryGroup::P
Run from the repository root:
moon bench ./bench/punctperf --target native
moon bench ./bench/punctperf --target wasm-gc
moon bench ./bench/punctperf --target wasm
The benchmark uses one code point per 97 scalar values, 11,486 characters in
all. Each iteration of the corpus cases visits the whole sample, so it measures
the predicate without the per-call benchmark harness dominating. The named
single-character cases include punctuation and non-punctuation code points from
ASCII, CJK, marks, and emoji; their reported time includes the @bench call
overhead, while the corpus cases amortize it.
Example results
One run on arm64, using the corpus cases (11,486 characters):
| Target | is_punctuation |
general_category(...) is P |
Speedup |
|---|---|---|---|
| native | 5.19 µs (0.45 ns/char) | 39.56 µs (3.44 ns/char) | 7.6× |
| wasm-gc | 10.65 µs (0.93 ns/char) | 75.84 µs (6.60 ns/char) | 7.1× |
| wasm | 13.66 µs (1.19 ns/char) | 154.42 µs (13.44 ns/char) | 11.3× |
The named single-character cases include the @bench call overhead, so their
reported difference is smaller; use the corpus cases for throughput.
1# Punctuation benchmark23Compare the dedicated punctuation predicate with the General_Category group4lookup:56```moonbit7@unicode.is_punctuation(c)8@unicode.general_category(c).group() is @unicode.GeneralCategoryGroup::P9```1011Run from the repository root:1213```sh14moon bench ./bench/punctperf --target native15moon bench ./bench/punctperf --target wasm-gc16moon bench ./bench/punctperf --target wasm17```1819The benchmark uses one code point per 97 scalar values, 11,486 characters in20all. Each iteration of the corpus cases visits the whole sample, so it measures21the predicate without the per-call benchmark harness dominating. The named22single-character cases include punctuation and non-punctuation code points from23ASCII, CJK, marks, and emoji; their reported time includes the `@bench` call24overhead, while the corpus cases amortize it.2526## Example results2728One run on arm64, using the corpus cases (11,486 characters):2930| Target | `is_punctuation` | `general_category(...) is P` | Speedup |31| --- | ---: | ---: | ---: |32| native | 5.19 µs (0.45 ns/char) | 39.56 µs (3.44 ns/char) | 7.6× |33| wasm-gc | 10.65 µs (0.93 ns/char) | 75.84 µs (6.60 ns/char) | 7.1× |34| wasm | 13.66 µs (1.19 ns/char) | 154.42 µs (13.44 ns/char) | 11.3× |3536The named single-character cases include the `@bench` call overhead, so their37reported difference is smaller; use the corpus cases for throughput.38# Punctuation benchmark Compare the dedicated punctuation predicate with the General_Category group lookup: ```moonbit @unicode.is_punctuation(c) @unicode.general_category(c).group() is @unicode.GeneralCategoryGroup::P ``` Run from the repository root: ```sh moon bench ./bench/punctperf --target native moon bench ./bench/punctperf --target wasm-gc moon bench ./bench/punctperf --target wasm ``` The benchmark uses one code point per 97 scalar values, 11,486 characters in all. Each iteration of the corpus cases visits the whole sample, so it measures the predicate without the per-call benchmark harness dominating. The named single-character cases include punctuation and non-punctuation code points from ASCII, CJK, marks, and emoji; their reported time includes the `@bench` call overhead, while the corpus cases amortize it. ## Example results One run on arm64, using the corpus cases (11,486 characters): | Target | `is_punctuation` | `general_category(...) is P` | Speedup | | --- | ---: | ---: | ---: | | native | 5.19 µs (0.45 ns/char) | 39.56 µs (3.44 ns/char) | 7.6× | | wasm-gc | 10.65 µs (0.93 ns/char) | 75.84 µs (6.60 ns/char) | 7.1× | | wasm | 13.66 µs (1.19 ns/char) | 154.42 µs (13.44 ns/char) | 11.3× | The named single-character cases include the `@bench` call overhead, so their reported difference is smaller; use the corpus cases for throughput.