Created
February 8, 2016 05:05
-
-
Save zentetsukenz/2ef23126ce6ec5dafdc1 to your computer and use it in GitHub Desktop.
Benchmark somethings and get the raw result in file
This file contains hidden or 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
# 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