Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 182 lines (150 sloc) 3.663 kb
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
1 require File.expand_path('herbs_helper')
8c9988b @mattetti started working on IO
authored
2
3 n = 4_000
4 o = 10_000
5 p = 50_000
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
6
7 def clear_ios
8 ObjectSpace.each_object(IO) {|x| x.close unless (x.closed? || x.inspect =~ /STD|fixtures/i) }
9 end
10
8c9988b @mattetti started working on IO
authored
11 Benchmark.bm do |b|
12 small_origin = File.open('fixtures/jules.txt')
13 large_origin = File.open('fixtures/verne.txt')
14
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
15 b.bench("new\n", :macruby => false) do
8c9988b @mattetti started working on IO
authored
16 p.times do
17 IO.new( 1, "w" )
18 end
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
19 end
8c9988b @mattetti started working on IO
authored
20
21 if IO.respond_to?(:binread)
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
22 b.bench("binread\n") do
8c9988b @mattetti started working on IO
authored
23 n.times do
24 IO.binread('fixtures/verne.txt')
25 end
26 end
27 end
28
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
29 b.bench("copy_stream (small file)\n", :macruby => false) do
8c9988b @mattetti started working on IO
authored
30 n.times do
31 IO.copy_stream('fixtures/jules.txt', 'fixtures/tmp', 10, 10)
32 end
33 end
34
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
35 b.bench("copy_stream (big file)\n", :macruby => false) do
8c9988b @mattetti started working on IO
authored
36 n.times do
37 IO.copy_stream('fixtures/verne.txt', 'fixtures/tmp', 40, 40)
38 end
39 end
02f5a49 @mattetti last tweaks
authored
40
8c9988b @mattetti started working on IO
authored
41 destination = File.open('fixtures/tmp', 'w+')
42 # not running on MacRuby atm
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
43 b.bench("copy_stream using IO sources (small file)\n", :macruby => false) do
44 n.times do
45 IO.copy_stream(small_origin, destination, 10, 10)
46 end
47 end
8c9988b @mattetti started working on IO
authored
48
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
49 b.bench("copy_stream using IO sources (big file)\n", :macruby => false) do
50 n.times do
51 IO.copy_stream(large_origin, destination, 40, 40)
52 end
53 end
8c9988b @mattetti started working on IO
authored
54
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
55 b.bench("foreach (small file)\n") do
8c9988b @mattetti started working on IO
authored
56 o.times do
57 IO.foreach('fixtures/jules.txt'){|x| x }
58 end
59 end
60
61
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
62 b.bench("foreach (large file)\n") do
8c9988b @mattetti started working on IO
authored
63 100.times do
64 IO.foreach('fixtures/verne.txt'){|x| x }
65 end
66 end
67
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
68 b.bench("open\n", :macruby => false) do
8c9988b @mattetti started working on IO
authored
69 p.times do |i|
70 IO.open(1, "w"){|io| }
71 end
72 end
73
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
74 b.bench("pipe\n") do
8c9988b @mattetti started working on IO
authored
75 25_000.times do |i|
76 rd, wr = IO.pipe
77 rd.close
78 wr.close
79 end
80 end
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
81
82 clear_ios
8c9988b @mattetti started working on IO
authored
83
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
84 b.bench("popen\n") do
8c9988b @mattetti started working on IO
authored
85 150.times do |i|
86 IO.popen("uname")
87 end
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
88 end
8c9988b @mattetti started working on IO
authored
89
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
90 clear_ios
8c9988b @mattetti started working on IO
authored
91
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
92 b.bench("read (small file)\n") do
8c9988b @mattetti started working on IO
authored
93 n.times do
94 IO.read('fixtures/jules.txt')
95 end
96 end
97
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
98 b.bench("read (big file)\n") do
8c9988b @mattetti started working on IO
authored
99 o.times do
100 IO.read('fixtures/verne.txt', 1_000)
101 end
102 end
103
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
104 b.bench("readlines (small file)\n") do
8c9988b @mattetti started working on IO
authored
105 o.times do
106 IO.readlines('fixtures/jules.txt')
107 end
108 end
109
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
110 b.bench("readlines (large file)\n") do
8c9988b @mattetti started working on IO
authored
111 150.times do
112 IO.readlines('fixtures/verne.txt')
113 end
114 end
115
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
116 clear_ios
8c9988b @mattetti started working on IO
authored
117
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
118 # b.bench("sysopen (small file) & close\n") do
119 # 250.times do
120 # IO.sysopen('fixtures/jules.txt')
121 # end
122 # end
123 #
124 # ObjectSpace.each_object(IO) {|x| x.close unless (x.closed? || x.inspect =~ /STD/i) }
125 #
126 # b.bench("sysopen (large file)\n") do
127 # 150.times do |n|
128 # IO.sysopen('fixtures/verne.txt')
129 # end
130 # end
131 #
132 # clear_ios
8c9988b @mattetti started working on IO
authored
133
134 class DummyIO; def to_io; STDOUT; end; end
135 dio = DummyIO.new
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
136 b.bench("try_convert obj\n") do
8c9988b @mattetti started working on IO
authored
137 p.times do
138 IO.try_convert(dio)
139 end
140 end
141
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
142 b.bench("try_convert str\n") do
8c9988b @mattetti started working on IO
authored
143 p.times do
144 IO.try_convert("dio")
145 end
146 end
147
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
148 b.bench("<<\n") do
8c9988b @mattetti started working on IO
authored
149 100_000.times do
150 STDOUT << ""
151 end
152 end
153
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
154 b.bench("binmode\n") do
8c9988b @mattetti started working on IO
authored
155 10_000.times do
156 i = IO.new(1); i.binmode;
157 end
158 end
159
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
160 b.bench("binmode?\n", :macruby => false) do
8c9988b @mattetti started working on IO
authored
161 200_000.times do
162 small_origin.binmode?
163 end
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
164 end
8c9988b @mattetti started working on IO
authored
165
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
166 b.bench("chars (small file)\n") do
8c9988b @mattetti started working on IO
authored
167 p.times do
168 small_origin.chars
169 end
170 end
171
123ae3d @mattetti added an option to not run a benchmark on an implementation
authored
172 b.bench("chars (large file)\n") do
8c9988b @mattetti started working on IO
authored
173 p.times do
174 large_origin.chars
175 end
176 end
177
178 small_origin.close
179 large_origin.close
180 destination.close
181
182 end
Something went wrong with that request. Please try again.