File: convert-char.rb

package info (click to toggle)
tomoe 0.6.0-1.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 51,396 kB
  • sloc: xml: 1,387,526; ansic: 11,515; sh: 9,072; ruby: 1,344; python: 762; makefile: 450
file content (46 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
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
require "benchmark"

benchmark_dir = File.expand_path(File.dirname(__FILE__))
top_dir = File.expand_path(File.join(benchmark_dir, ".."))
test_dir = File.join(top_dir, "test")
$LOAD_PATH.unshift(File.join(top_dir, "bindings", "ruby", ".libs"))
$LOAD_PATH.unshift(File.join(top_dir, "bindings", "ruby"))
$LOAD_PATH.unshift(File.join(test_dir))

require "tomoe-test-utils"

xml = <<-XML
  <character>
    <utf8>あ</utf8>
    <strokes>
      <stroke>
        <point x="180" y="193"/>
        <point x="830" y="226"/>
      </stroke>
      <stroke>
        <point x="490" y="33"/>
        <point x="483" y="670"/>
        <point x="606" y="840"/>
      </stroke>
      <stroke>
        <point x="746" y="343"/>
        <point x="496" y="766"/>
        <point x="273" y="800"/>
        <point x="176" y="680"/>
        <point x="286" y="496"/>
        <point x="606" y="463"/>
        <point x="800" y="573"/>
        <point x="826" y="746"/>
        <point x="760" y="833"/>
      </stroke>
    </strokes>
  </character>
XML

n = 5000
Benchmark.bmbm do |x|
  x.report("XML -> TomoeChar (##{n})") {n.times {Tomoe::Char.new(xml)}}
  GC.start
  char = Tomoe::Char.new(xml)
  x.report("TomoeChar -> XML (##{n})") {n.times {char.to_xml}}
end