summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-12-28 12:08:14 +0100
committerKornelius Kalnbach <murphy@rubychan.de>2016-12-28 12:08:14 +0100
commitffdd9ddb5cb5ab19a04ee0a714fa08d8d70f3437 (patch)
treebb6b72d10a189e674829c10cbd26abcce965d233
parentc999deb1e932b3290561a58923603eb87809c8df (diff)
parent935f003b2c15d6effb637abfc2ba40c20ad4ba98 (diff)
downloadcoderay-ffdd9ddb5cb5ab19a04ee0a714fa08d8d70f3437.tar.gz
Merge branch 'master' into possible-speedups
-rw-r--r--bench/bench.rb10
-rw-r--r--rake_tasks/benchmark.rake2
2 files changed, 8 insertions, 4 deletions
diff --git a/bench/bench.rb b/bench/bench.rb
index 92f9d07..34ea9f9 100644
--- a/bench/bench.rb
+++ b/bench/bench.rb
@@ -15,7 +15,7 @@ raise 'Example file is empty.' if data.empty?
format = ARGV.fetch(1, 'html').downcase
encoder = CodeRay.encoder(format)
-size = ARGV.fetch(2, 1000).to_i * 1000
+size = ARGV.fetch(2, 2000).to_i * 1000
unless size.zero?
data += data until data.size >= size
data = data[0, size]
@@ -23,14 +23,18 @@ end
size = data.size
puts "encoding %d kB of #{lang} code to #{format}..." % [(size / 1000.0).round]
-n = ARGV.fetch(3, 5).to_s[/\d+/].to_i
+n = ARGV.fetch(3, 10).to_s[/\d+/].to_i
require 'profile' if ARGV.include? '-p'
+times = []
n.times do |i|
time = Benchmark.realtime { encoder.encode(data, lang) }
puts "run %d: %5.2f s, %4.0f kB/s" % [i + 1, time, size / time / 1000.0]
+ times << time
end
-STDIN.gets if ARGV.include? '-w'
+times_sum = times.inject(0) { |time, sum| sum + time }
+puts 'Average time: %5.2f s, %4.0f kB/s' % [times_sum / times.size, (size * n) / times_sum / 1000.0]
+puts 'Best time: %5.2f s, %4.0f kB/s' % [times.min, size / times.min / 1000.0]
__END__
Usage:
diff --git a/rake_tasks/benchmark.rake b/rake_tasks/benchmark.rake
index 2e38b57..8edeffb 100644
--- a/rake_tasks/benchmark.rake
+++ b/rake_tasks/benchmark.rake
@@ -1,6 +1,6 @@
desc 'Do a benchmark'
task :benchmark do
- ruby 'bench/bench.rb ruby html 3000'
+ ruby 'bench/bench.rb ruby html'
end
task :bench => :benchmark