unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

bench/xlang/report_wbtest.mbt
1///|2/// Two rounds of two harnesses: the report keeps the fastest round, compares3/// per unit with the baseline and averages geometrically over the inputs.4fn sample_results() -> Results {5  let results = Results(Map([]))6  let outputs = [7    (8      "moonbit-native",9      (10        #|	norm/nfc/a	200	100	711        #|	norm/nfc/b	800	100	912        #|	idna/to_ascii/x	50	1	1513        #|not a result row14      ),15    ),16    (17      "moonbit-native",18      (19        #|	norm/nfc/a	100	100	720        #|	norm/nfc/b	1000	100	921        #|	idna/to_ascii/x	55	1	1522      ),23    ),24    (25      "rust",26      (27        #|fast	norm/nfc/a	50	100	728        #|fast	norm/nfc/b	400	100	929        #|slow	norm/nfc/a	4e2	100	830        #|idna	idna/to_ascii/x	25000	1	-31      ),32    ),33  ]34  for output in outputs {35    for row in parse_rows(output.0, output.1) {36      results.add(row)37    }38  }39  results40}4142///|43test "rows are parsed and the fastest round is kept" {44  let results = sample_results()45  guard results.cell("moonbit-native", "norm/nfc/a") is Some(cell) else {46    fail("missing cell")47  }48  inspect(cell.fastest, content="100")49  inspect(cell.slowest, content="200")50  inspect(cell.cost(), content="1")51  inspect(results.cell("rust slow", "norm/nfc/b") is None, content="true")52}5354///|55test "numbers keep two decimals below 100" {56  inspect(format_number(0.004), content="0.00")57  inspect(format_number(1.0), content="1.00")58  inspect(format_number(12.345), content="12.35")59  inspect(format_number(99.999), content="100.00")60  inspect(format_number(1234.5), content="1235")61}6263///|64test "report" {65  inspect(66    sample_results().report(rounds=2, detail=true),67    content=(68      #|# Cross-language Unicode benchmark69      #|70      #|Each cell is the fastest of 2 round(s). In parentheses: the time71      #|relative to `moonbit-native` on the same cases, so above 1 means slower72      #|than MoonBit native and below 1 means faster.73      #|74      #|### norm: geometric mean over inputs (ns per code point)75      #|76      #|| operation | moonbit-native | rust fast | rust slow |77      #||---|---|---|---|78      #|| nfc | 2.83 | 1.41 (0.50x) | 4.00 (4.00x) |79      #|80      #|### norm/nfc (ns per code point)81      #|82      #|| input | moonbit-native | rust fast | rust slow |83      #||---|---|---|---|84      #|| a | 1.00 | 0.50 (0.50x) | 4.00 (4.00x) |85      #|| b | 8.00 | 4.00 (0.50x) | – |86      #|87      #|### idna: geometric mean over inputs (ns per call)88      #|89      #|| operation | moonbit-native | rust idna |90      #||---|---|---|91      #|| to_ascii | 50.00 | 25000 (500x) |92      #|93      #|### idna/to_ascii (ns per call)94      #|95      #|| input | moonbit-native | rust idna |96      #||---|---|---|97      #|| x | 50.00 | 25000 (500x) |98      #|99      #|### Checks100      #|101      #|Implementations disagree on these cases:102      #|103      #|- norm/nfc/a: 7 from moonbit-native, rust fast; 8 from rust slow104      #|105      #|### Noise (median of slowest round / fastest round)106      #|107      #|| column | spread |108      #||---|---|109      #|| moonbit-native | 1.25x |110      #|| rust fast | 1.00x |111      #|| rust slow | 1.00x |112      #|| rust idna | 1.00x |113      #|114    ),115  )116}117