Skip to content

Commit

Permalink
Use benchmark-ips for benchs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Pfenniger committed Jul 14, 2013
1 parent 3cb5a6e commit 9079b8f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ group :development do
gem 'rdoc'
end
group :test do
gem 'rspec'
gem 'benchmark-ips'
gem 'rake'
gem 'rspec'
end
60 changes: 24 additions & 36 deletions spec/bench.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
require 'benchmark/ips'

$:.unshift File.expand_path('../../lib', __FILE__)
require 'lines'

module Kernel
def bm(name = nil, &what)
start = Time.now.to_f
count = 0
max = 0.5
name ||= what.source_location.join(':')
$stdout.write "#{name} : "
while Time.now.to_f - start < max
yield
count += 1
end
$stdout.puts "%0.3f fps" % (count / max)
end
end

class FakeIO
def write(*a)
end
Expand All @@ -30,29 +17,30 @@ def write(*a)

EX = (raise "FOO" rescue $!)

Lines.use(FakeIO.new, globals)
bm "FakeIO write" do
Lines.log EX
end
Benchmark.ips do |x|
x.report "FakeIO write" do |n|
Lines.use(FakeIO.new, globals)
n.times{ Lines.log EX }
end

dev_null = File.open('/dev/null', 'w')
Lines.use(dev_null, globals)
bm "/dev/null write" do
Lines.log EX
end
x.report "/dev/null write" do |n|
dev_null = File.open('/dev/null', 'w')
Lines.use(dev_null, globals)
n.times{ Lines.log EX }
end

Lines.use(Syslog, globals)
bm "syslog write" do
Lines.log EX
end
x.report "syslog write" do |n|
Lines.use(Syslog, globals)
n.times{ Lines.log EX }
end

real_file = File.open('real_file.log', 'w')
Lines.use(real_file, globals)
bm "real file" do
Lines.log EX
end
x.report "real file" do |n|
real_file = File.open('real_file.log', 'w')
Lines.use(real_file, globals)
n.times{ Lines.log EX }
end

bm "real file logger" do
Lines.logger.info "Ahoi this is a really cool option"
x.report "real file logger" do |n|
n.times{ Lines.logger.info "Ahoi this is a really cool option" }
end
end

0 comments on commit 9079b8f

Please sign in to comment.