diff options
author | murphy <murphy@rubychan.de> | 2011-04-17 14:06:05 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2011-04-17 14:06:05 +0000 |
commit | 0203a17444d94b393ffce0e0a00f9abaaea06277 (patch) | |
tree | fff168d0b26f2ad53707fe81a18832a898026830 | |
parent | d8c9161dc174e364fc4a3e8e9df1d45262c5cc4a (diff) | |
download | coderay-0203a17444d94b393ffce0e0a00f9abaaea06277.tar.gz |
updated benchmark script: use Nx param to repeat x times, KB means kilo (1000)
-rw-r--r-- | bench/bench.rb | 48 | ||||
-rw-r--r-- | rake_tasks/benchmark.rake | 2 |
2 files changed, 24 insertions, 26 deletions
diff --git a/bench/bench.rb b/bench/bench.rb index f73b1c9..48de81a 100644 --- a/bench/bench.rb +++ b/bench/bench.rb @@ -62,8 +62,8 @@ n = ARGV.find { |a| a[/^N/] } N = if n then n[/\d+/].to_i else 1 end $filename = ARGV.include?('strange') ? 'strange' : 'example' -(compare ? 1 : 5).times do Benchmark.bm(20) do |bm| +N.times do data = nil File.open(here("#$filename." + lang), 'rb') { |f| data = f.read } @@ -86,29 +86,27 @@ Benchmark.bm(20) do |bm| } $hl = CodeRay.encoder(format, options) unless $dump_output time = bm.report('CodeRay') do - N.times do - if $stream || true - if $dump_input - raise 'Can\'t stream dump.' - elsif $dump_output - raise 'Can\'t dump stream.' - end - $o = $hl.encode(data, lang, options) - @token_count = 253528 #$hl.token_stream.count rescue 1 + if $stream || true + if $dump_input + raise 'Can\'t stream dump.' + elsif $dump_output + raise 'Can\'t dump stream.' + end + $o = $hl.encode(data, lang, options) + @token_count = 253528 #$hl.token_stream.count rescue 1 + else + if $dump_input + tokens = CodeRay::Tokens.load data else - if $dump_input - tokens = CodeRay::Tokens.load data - else - tokens = CodeRay.scan(data, lang) - end - @token_count = tokens.count - p @token_count - tokens.optimize! if $optimize - if $dump_output - $o = tokens.optimize.dump - else - $o = tokens.encode($hl) - end + tokens = CodeRay.scan(data, lang) + end + @token_count = tokens.count + p @token_count + tokens.optimize! if $optimize + if $dump_output + $o = tokens.optimize.dump + else + $o = tokens.encode($hl) end end end @@ -121,9 +119,9 @@ Benchmark.bm(20) do |bm| FileUtils.copy 'test.dump', 'example.dump' if $dump_output end - time_real = time.real / N + time_real = time.real - puts "\t%7.2f KB/s (%d.%d KB)\t%0.2f KTok/s" % [((@size / 1024.0) / time_real), @size / 1024, @size % 1024, ((@token_count / 1000.0) / time_real)] + puts "\t%7.2f KB/s (%d.%d KB)\t%0.2f KTok/s" % [((@size / 1000.0) / time_real), @size / 1000, @size % 1000, ((@token_count / 1000.0) / time_real)] puts $o if ARGV.include? '-o' if compare diff --git a/rake_tasks/benchmark.rake b/rake_tasks/benchmark.rake index 71c1c96..c6d5ebb 100644 --- a/rake_tasks/benchmark.rake +++ b/rake_tasks/benchmark.rake @@ -1,7 +1,7 @@ desc 'Do a benchmark' task :benchmark do ruby "-v" - ruby "-Ilib bench/bench.rb ruby div 1000" + ruby "-wIlib bench/bench.rb ruby div 1000 N5" end task :bench => :benchmark |