1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/usr/bin/env ruby
require 'json'
require 'optparse'
require 'rbconfig'
require 'benchmark/ips'
@source, @gem = false
OptionParser.new do |opt|
opt.banner = "Usage: #{File.basename $0} [--gem|--source]"
opt.separator ""
opt.separator "Benchmark IPS (iterations per second) changes between"
opt.separator "source version of sys-proctable and previous gem"
opt.separator "version."
opt.separator ""
opt.separator "Requires that the both the source version of the gem"
opt.separator "be installed (run `rake install` to do this after"
opt.separator "each of your changes) and version installed via"
opt.separator "rubygems."
opt.separator ""
opt.separator "To run, call with `--gem` two times, and then with "
opt.separator "`--source` two times again."
opt.separator ""
opt.on("--source") { @source = true }
opt.on("--gem") { @gem = true }
end.parse!
if @source && !@gem
# Being paranoid here and making sure we get the version installed to
# sitelibdir
require File.join(RbConfig::CONFIG["sitelibdir"], "sys", "proctable")
else
@gem = true
require 'sys-proctable'
end
Benchmark.ips do |bench|
bench.report("Block form - pre patch") do
(puts "ERR: Please run with --gem"; exit 1) unless @gem
Sys::ProcTable.ps {}
end
bench.report("Non-block form - pre patch") do
(puts "ERR: Please run with --gem"; exit 1) unless @gem
Sys::ProcTable.ps
end
bench.report("Block form - post patch") do
(puts "ERR: Please run with --source"; exit 1) unless @source
Sys::ProcTable.ps {}
end
bench.report("Non-block form - post patch") do
(puts "ERR: Please run with --source"; exit 1) unless @source
Sys::ProcTable.ps
end
bench.hold! "bench_ips_ps.results"
bench.compare!
end
|