Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 50 lines (41 sloc) 0.972 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# -*- encoding: utf-8 -*-

require "benchmark"

require "unicode_utils/char_name"
require "unicode_utils/codepoint"

def all_char_names
  UnicodeUtils::Codepoint::RANGE.each { |code_point|
    UnicodeUtils.char_name(code_point)
  }
end

def cjk_char_names
  [0x3400..0x4DB5, 0x4E00..0x9FC3, 0x20000..0x2A6D6].each { |range|
    range.each { |code_point|
      UnicodeUtils.char_name(code_point)
    }
  }
end

def hangul_syllable_char_names
  (0xAC00..0xD7A3).each { |code_point|
    UnicodeUtils.char_name(code_point)
  }
end

def name_map_lookup(code_point)
  UnicodeUtils::NAME_MAP[code_point]
end

puts "UnicodeUtils.char_name benchmarks"

Benchmark.bm { |x|
  x.report("baseline") {
    UnicodeUtils::Codepoint::RANGE.each { |code_point|
      name_map_lookup(code_point)
    }
  }
  x.report("all code points") {
    all_char_names
  }
  x.report("CJK UNIFIED IDEOGRAPH") {
    cjk_char_names
  }
  x.report("HANGUL SYLLABLE") {
    hangul_syllable_char_names
  }
}
Something went wrong with that request. Please try again.