summaryrefslogtreecommitdiff
path: root/bench/bench.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bench/bench.rb')
-rw-r--r--bench/bench.rb44
1 files changed, 24 insertions, 20 deletions
diff --git a/bench/bench.rb b/bench/bench.rb
index c9382b8..4d4200a 100644
--- a/bench/bench.rb
+++ b/bench/bench.rb
@@ -45,7 +45,7 @@ if format == 'comp'
require 'syntax'
require 'syntax/convertors/html.rb'
rescue LoadError
- raise 'This requires Syntax! (Try % gem install syntax)'
+ puts 'Syntax no found!! (Try % gem install syntax)'
end
end
@@ -66,6 +66,7 @@ b = ARGV.find { |a| a[/^B/] }
BoldEvery = if b then b[/\d+/].to_i else 10 end
$filename = ARGV.include?('strange') ? 'strange' : 'example'
+(compare ? 1 : 5).times do
Benchmark.bm(20) do |bm|
data = nil
@@ -133,27 +134,29 @@ Benchmark.bm(20) do |bm|
puts $o if ARGV.include? '-o'
if compare
- time = bm.report('Syntax') do
- c = Syntax::Convertors::HTML.for_syntax lang
- puts 'No Syntax syntax found!' if c.tokenizer.is_a? Syntax::Default
- begin
- v = $VERBOSE
- $VERBOSE = nil
- N.times do
- output = c.convert(data)
+ if defined? Syntax
+ time = bm.report('Syntax') do
+ c = Syntax::Convertors::HTML.for_syntax lang
+ puts 'No Syntax syntax found!' if c.tokenizer.is_a? Syntax::Default
+ begin
+ v = $VERBOSE
+ $VERBOSE = nil
+ N.times do
+ output = c.convert(data)
+ end
+ $VERBOSE = v
+ rescue => boom
+ output = boom.inspect
end
- $VERBOSE = v
- rescue => boom
- output = boom.inspect
- end
- Dir.chdir(here) do
- File.open('test.syntax.' + format, 'wb') do |f|
- f.write '<html><head><style>%s</style></head><body><div class="ruby">%s</div></body></html>' % [DATA.read, output]
+ Dir.chdir(here) do
+ File.open('test.syntax.' + format, 'wb') do |f|
+ f.write '<html><head><style>%s</style></head><body><div class="ruby">%s</div></body></html>' % [DATA.read, output]
+ end
end
+ $file_created << ", test.syntax.#{format}"
end
- $file_created << ", test.syntax.#{format}"
+ puts "\t%7.2f KB/sec" % ((@size / 1024.0) / time.real)
end
- puts "\t%7.2f KB/sec" % ((@size / 1024.0) / time.real)
=begin
time = bm.report('SilverCity') do
@@ -170,9 +173,9 @@ Benchmark.bm(20) do |bm|
time = bm.report('Pygments') do
Dir.chdir(here) do
Dir.chdir File.expand_path('~/Python/pygments') do
- File.open('input-data', 'w') { |f| f.write data }
+ File.open('input-data', 'wb') { |f| f.write data }
N.times do
- `python pygmentize -l#{lang} -fhtml input-data > /dev/null`
+ `pygmentize -O encoding=utf-8 -l#{lang} -fhtml input-data > /dev/null`
end
end
end
@@ -182,6 +185,7 @@ Benchmark.bm(20) do |bm|
end
end
+end
puts "Files created: #$file_created"
STDIN.gets if ARGV.include? 'wait'