-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bench mark script to help measure performance impact of changes
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
1 parent
5bb17a0
commit f30e3b1
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ gemspec | |
|
||
gem 'rake' | ||
gem 'pry' | ||
gem "whysoslow" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [31m+ 0 MB, 0%[0m | ||
|
||
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 [32m- 0 MB, 0%[0m | ||
|
||
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 [32m- 0 MB, 0%[0m | ||
|
||
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 [31m+ 4 MB, 10%[0m | ||
|
||
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 [32m- 0 MB, 0%[0m | ||
|
||
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 [31m+ 2 MB, 6%[0m | ||
|
||
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 [31m+ 49 MB, 110%[0m | ||
|
||
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 [31m+ 492 MB, 527%[0m | ||
|
||
user system total real | ||
time 770.0 ms 900.0 ms 5290.0 ms 61803.114 ms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|