Skip to content

Commit ffdd9dd

Browse files
committed
Merge branch 'master' into possible-speedups
2 parents c999deb + 935f003 commit ffdd9dd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

bench/bench.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@
1515
format = ARGV.fetch(1, 'html').downcase
1616
encoder = CodeRay.encoder(format)
1717

18-
size = ARGV.fetch(2, 1000).to_i * 1000
18+
size = ARGV.fetch(2, 2000).to_i * 1000
1919
unless size.zero?
2020
data += data until data.size >= size
2121
data = data[0, size]
2222
end
2323
size = data.size
2424
puts "encoding %d kB of #{lang} code to #{format}..." % [(size / 1000.0).round]
2525

26-
n = ARGV.fetch(3, 5).to_s[/\d+/].to_i
26+
n = ARGV.fetch(3, 10).to_s[/\d+/].to_i
2727
require 'profile' if ARGV.include? '-p'
28+
times = []
2829
n.times do |i|
2930
time = Benchmark.realtime { encoder.encode(data, lang) }
3031
puts "run %d: %5.2f s, %4.0f kB/s" % [i + 1, time, size / time / 1000.0]
32+
times << time
3133
end
3234

33-
STDIN.gets if ARGV.include? '-w'
35+
times_sum = times.inject(0) { |time, sum| sum + time }
36+
puts 'Average time: %5.2f s, %4.0f kB/s' % [times_sum / times.size, (size * n) / times_sum / 1000.0]
37+
puts 'Best time: %5.2f s, %4.0f kB/s' % [times.min, size / times.min / 1000.0]
3438

3539
__END__
3640
Usage:

rake_tasks/benchmark.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
desc 'Do a benchmark'
22
task :benchmark do
3-
ruby 'bench/bench.rb ruby html 3000'
3+
ruby 'bench/bench.rb ruby html'
44
end
55

66
task :bench => :benchmark

0 commit comments

Comments
 (0)