Project

General

Profile

Feature #2372 ยป test.rb

wanabe (_ wanabe), 11/15/2009 09:21 PM

 
1
require 'tempfile'
2
require 'benchmark'
3

    
4
Benchmark.bm(27) do |bm|
5
  [["short", "hoge", 50000],
6
   ["long ", "Hello world!  " * 1000, 1000]].each do |type, str, max|
7

    
8
    f = Tempfile.new('temp-read')
9
    f.write str
10
    f.close
11

    
12
    ["r", "r:us-ascii:utf-8", "r:us-ascii:utf-16le",
13
     "rb", "rb:us-ascii:utf-8", "rb:us-ascii:utf-16le"].each do |mode|
14
      open(f.path, mode) do |r|
15
        bm.report("#{type} #{mode}") do
16
          max.times do
17
            r.seek 0
18
            r.read
19
          end
20
        end
21
      end
22
    end
23
  end
24
end