Skip to content

Commit

Permalink
Add a bench mark script to help measure performance impact of changes
Browse files Browse the repository at this point in the history
This add a bench mark script that measures running cmds multiple
times and writes the results so we can know how a change impacts
performance.
  • Loading branch information
kellyredding committed Nov 7, 2013
1 parent 5bb17a0 commit f30e3b1
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gemspec

gem 'rake'
gem 'pry'
gem "whysoslow"
80 changes: 80 additions & 0 deletions bench/results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
echo hi: 1 times
----------------
whysoslow? ..

mem @ start 38 MB ??
mem @ finish 38 MB + 0 MB, 0%

user system total real
time 0.0 ms 0.0 ms 0.0 ms 62.42 ms

echo hi: 10 times
-----------------
whysoslow? ..

mem @ start 38 MB ??
mem @ finish 38 MB - 0 MB, 0%

user system total real
time 10.0 ms 10.0 ms 40.0 ms 619.93 ms

echo hi: 100 times
------------------
whysoslow? ..

mem @ start 38 MB ??
mem @ finish 38 MB - 0 MB, 0%

user system total real
time 50.0 ms 50.0 ms 330.0 ms 6176.346 ms

echo hi: 1000 times
-------------------
whysoslow? ..

mem @ start 38 MB ??
mem @ finish 42 MB + 4 MB, 10%

user system total real
time 500.0 ms 540.0 ms 3280.0 ms 61703.161 ms

cat test/support/bigger-than-64k.txt: 1 times
---------------------------------------------
whysoslow? ..

mem @ start 42 MB ??
mem @ finish 42 MB - 0 MB, 0%

user system total real
time 0.0 ms 0.0 ms 0.0 ms 62.127 ms

cat test/support/bigger-than-64k.txt: 10 times
----------------------------------------------
whysoslow? ..

mem @ start 42 MB ??
mem @ finish 44 MB + 2 MB, 6%

user system total real
time 10.0 ms 10.0 ms 50.0 ms 620.075 ms

cat test/support/bigger-than-64k.txt: 100 times
-----------------------------------------------
whysoslow? ..

mem @ start 44 MB ??
mem @ finish 93 MB + 49 MB, 110%

user system total real
time 80.0 ms 100.0 ms 520.0 ms 6185.163 ms

cat test/support/bigger-than-64k.txt: 1000 times
------------------------------------------------
whysoslow? ..

mem @ start 93 MB ??
mem @ finish 585 MB + 492 MB, 527%

user system total real
time 770.0 ms 900.0 ms 5290.0 ms 61803.114 ms

29 changes: 29 additions & 0 deletions bench/runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'whysoslow'
require 'scmd'

class ScmdBenchRunner

attr_reader :result

def self.run(*args)
self.new(*args).run
end

def initialize(printer_io, cmd, num_times = 10)
@cmd = cmd
@proc = proc do
num_times.times{ cmd.run! }
end

@printer = Whysoslow::DefaultPrinter.new(printer_io, {
:title => "#{@cmd.cmd_str}: #{num_times} times",
:verbose => true
})
@runner = Whysoslow::Runner.new(@printer)
end

def run
@runner.run &@proc
end

end
47 changes: 47 additions & 0 deletions script/bench.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# $ bundle exec ruby script/bench.rb

require 'bench/runner'

class ScmdBenchLogger

def initialize(file_path)
@file = File.open(file_path, 'w')
@ios = [@file, $stdout]
yield self
@file.close
end

def method_missing(meth, *args, &block)
@ios.each do |io|
io.respond_to?(meth.to_s) ? io.send(meth.to_s, *args, &block) : super
end
end

def respond_to?(*args)
@ios.first.respond_to?(args.first.to_s) ? true : super
end

end

def run_cmd(logger, *args)
GC.disable

ScmdBenchRunner.run(logger, *args)
logger.puts

GC.enable
GC.start
end

ScmdBenchLogger.new('bench/results.txt') do |logger|
run_cmd(logger, Scmd.new("echo hi"), 1)
run_cmd(logger, Scmd.new("echo hi"), 10)
run_cmd(logger, Scmd.new("echo hi"), 100)
run_cmd(logger, Scmd.new("echo hi"), 1000)

run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 1)
run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 10)
run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 100)
run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 1000)
end

0 comments on commit f30e3b1

Please sign in to comment.