Project

General

Profile

Feature #12275 » benchmark2.rb

tad (Tadashi Saito), 12/09/2017 05:46 PM

 
1
require 'benchmark'
2

    
3
N = 1000_000
4
s = 'あいうえお'.dump
5
t = 'あいうえお'.encode('UTF-16LE').dump
6

    
7
Benchmark.bm(25) do |bm|
8
  bm.report('eval') do
9
    N.times{eval(s)}
10
  end
11

    
12
  bm.report('undump') do
13
    N.times{s.undump}
14
  end
15

    
16
  bm.report('undump with force_encoding') do
17
    N.times{t.undump}
18
  end
19
end