unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

bench/lookupperf/lookupperf_bench_test.mbt
1///|2/// Every `step`-th scalar value below `limit`, skipping surrogates.3fn sample(step : Int32, limit : Int32) -> Array[Char] {4  let chars : Array[Char] = []5  for cp = 0; cp < limit; cp = cp + step {6    if cp < 0xD800 || cp > 0xDFFF {7      chars.push(cp.unsafe_to_char())8    }9  }10  chars11}1213///|14test "table lookups" (b : @bench.T) {15  // One code point per 97 scalar values covers every plane; one per 7 in the16  // BMP hits the dense regions of the smaller tables more often.17  let corpora = [("all", sample(97, 0x110000)), ("bmp", sample(7, 0x10000))]18  for (label, chars) in corpora {19    let name = "\{label}-\{chars.length()}"20    b.bench(name="is_mark/\{name}", fn() {21      let mut found = 022      for c in chars {23        if @general_category.is_mark(c) {24          found += 125        }26      }27      b.keep(found)28    })29    b.bench(name="is_composition_excluded/\{name}", fn() {30      let mut found = 031      for c in chars {32        if @composition.is_composition_excluded(c) {33          found += 134        }35      }36      b.keep(found)37    })38    b.bench(name="get_mirrored/\{name}", fn() {39      let mut sum = 040      for c in chars {41        sum += @bidi.get_mirrored(c, 1).to_int()42      }43      b.keep(sum)44    })45    b.bench(name="general_category_ordinal/\{name}", fn() {46      let mut sum = 047      for c in chars {48        sum += @general_category.lookup_general_category(c)49      }50      b.keep(sum)51    })52    b.bench(name="general_category_is_Ll/\{name}", fn() {53      let mut found = 054      for c in chars {55        if @ucd.general_category(c) is Ll {56          found += 157        }58      }59      b.keep(found)60    })61    b.bench(name="general_category_group_is_P/\{name}", fn() {62      let mut found = 063      for c in chars {64        if @ucd.general_category(c).group() is P {65          found += 166        }67      }68      b.keep(found)69    })70  }71}72