Skip to content

Instantly share code, notes, and snippets.

@zentetsukenz
Created February 8, 2016 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentetsukenz/2ef23126ce6ec5dafdc1 to your computer and use it in GitHub Desktop.
Save zentetsukenz/2ef23126ce6ec5dafdc1 to your computer and use it in GitHub Desktop.
Benchmark somethings and get the raw result in file
# gem install ascii_charts # if necessary
require 'ascii_charts'
require 'benchmark'
require './test.rb'
include Benchmark
class Runner
def self.run
new.run
end
def initialize
@params = {
some: 'thing'
}
end
def run
runner = Tester.new @params
runner.run
end
end
# ========================
# Graph
# ========================
if true
n_times = 100
n_concurrents = 40
puts "Time of #{n_times} with #{n_concurrents} concurrent jobs"
threads = []
d = []
n_concurrents.times do |t|
threads << Thread.new do
d[t] = []
n_times.times do |i|
d[t] << [i, Benchmark.realtime { Runner.run }]
end
puts "Plotting thread #{t}"
puts AsciiCharts::Cartesian.new(d[t]).draw
puts "Average time for thread #{t} is #{d[t].map { |s| s[1] }.inject(:+) / n_times}"
end
end
threads.each { |thr| thr.join }
puts "Overall average time for #{n_times} with #{n_concurrents} concurrents is"
puts d.map { |set| set.map { |s| s[1] }.inject(:+) }.inject(:+) / (n_times * n_concurrents)
File.open("benchmark_result_raw.txt", "w+") do |f|
f.write(d.map { |set| set.map { |s| s[1] } })
end
end
# ========================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment