public
Last active

  • Download Gist
bench.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
require 'rubygems'
require 'benchmark'
require 'bluecloth'
 
# results on Mac OS X 10.5.6, Ciore Duo 2 at 2.5 GHz
#
# also see graph of results:
#
# http://img.skitch.com/20090408-fp1sxu3fu7dm4296kqrmskgaqt.png
#
# [bluecloth-git (master)]$ ruby bench.rb
#
# Ruby version: MRI 1.8.6 (2008-03-03 rev 114), platform: universal-darwin9.0
#
# Benchmark Ruby BlueCloth processing of: http://daringfireball.net/projects/markdown/syntax.text
# file length = 11075
#
# running benchmark once.
#
# Rehearsal ------------------------------------------------------------------------------------------
# process README.md concatenated 1 times with BlueCloth 0.140000 0.010000 0.150000 ( 0.159116)
# process README.md concatenated 2 times with BlueCloth 0.330000 0.040000 0.370000 ( 0.398529)
# process README.md concatenated 4 times with BlueCloth 0.820000 0.140000 0.960000 ( 0.976002)
# process README.md concatenated 8 times with BlueCloth 2.130000 0.510000 2.640000 ( 2.683848)
# process README.md concatenated 16 times with BlueCloth 6.520000 2.090000 8.610000 ( 8.763092)
# process README.md concatenated 32 times with BlueCloth 22.370000 8.570000 30.940000 ( 31.517693)
# -------------------------------------------------------------------------------- total: 43.670000sec
#
# user system total real
# process README.md concatenated 1 times with BlueCloth 0.090000 0.010000 0.100000 ( 0.105123)
# process README.md concatenated 2 times with BlueCloth 0.220000 0.030000 0.250000 ( 0.250649)
# process README.md concatenated 4 times with BlueCloth 0.590000 0.100000 0.690000 ( 0.696880)
# process README.md concatenated 8 times with BlueCloth 1.810000 0.460000 2.270000 ( 2.298147)
# process README.md concatenated 16 times with BlueCloth 6.150000 2.110000 8.260000 ( 8.352241)
# process README.md concatenated 32 times with BlueCloth 22.210000 8.970000 31.180000 ( 31.484872)
#
# [bluecloth-git (master)]$ jruby bench.rb 2
#
# Ruby version: JRuby 1.8.6 (2009-04-08 rev 287) [i386-jruby1.3.0], platform: Java, version 1.6.0_07
#
# Benchmark Ruby BlueCloth processing of: http://daringfireball.net/projects/markdown/syntax.text
# file length = 11075
#
# running benchmark 2 times.
#
# Rehearsal ------------------------------------------------------------------------------------------
# process README.md concatenated 1 times with BlueCloth 0.535000 0.000000 0.535000 ( 0.535000)
# process README.md concatenated 2 times with BlueCloth 0.557000 0.000000 0.557000 ( 0.557000)
# process README.md concatenated 4 times with BlueCloth 0.672000 0.000000 0.672000 ( 0.671000)
# process README.md concatenated 8 times with BlueCloth 1.380000 0.000000 1.380000 ( 1.380000)
# process README.md concatenated 16 times with BlueCloth 4.277000 0.000000 4.277000 ( 4.277000)
# process README.md concatenated 32 times with BlueCloth 14.257000 0.000000 14.257000 ( 14.257000)
# -------------------------------------------------------------------------------- total: 21.678000sec
#
# user system total real
# process README.md concatenated 1 times with BlueCloth 0.068000 0.000000 0.068000 ( 0.068000)
# process README.md concatenated 2 times with BlueCloth 0.156000 0.000000 0.156000 ( 0.156000)
# process README.md concatenated 4 times with BlueCloth 0.404000 0.000000 0.404000 ( 0.404000)
# process README.md concatenated 8 times with BlueCloth 1.166000 0.000000 1.166000 ( 1.166000)
# process README.md concatenated 16 times with BlueCloth 3.984000 0.000000 3.984000 ( 3.984000)
# process README.md concatenated 32 times with BlueCloth 14.119000 0.000000 14.119000 ( 14.118000)
 
 
if RUBY_PLATFORM =~ /java/
include Java
@ruby_info = "Ruby version: JRuby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} rev #{RUBY_PATCHLEVEL}) [i386-jruby#{JRUBY_VERSION}]"
@ruby_info << ", platform: Java, version #{java.lang.System.getProperty('java.version')}"
else
@ruby_info = "Ruby version: MRI #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} rev #{RUBY_PATCHLEVEL})"
@ruby_info << ", platform: #{RUBY_PLATFORM}"
end
 
# @readme = File.read("PHP_Markdown_README.txt")
# found here:
# http://wpcal.firetree.net/wp-content/plugins/PHP%20Markdown%201.0.1k/PHP%20Markdown%20Readme.text
 
@readme = File.read("README.md")
# try this one instead:
# http://eigenclass.org/misc/README.md
@readme_files = []
(0..5).each do |i|
@readme_files << @readme * (2**i)
end
 
num = 32
test_iterations = ARGV.first.to_i
test_iterations = 1 unless test_iterations > 1
puts
puts @ruby_info
puts
puts "Benchmark Ruby BlueCloth processing of: http://daringfireball.net/projects/markdown/syntax.text"
puts "file length = #{@readme.length}"
puts
print "running benchmark "
if test_iterations == 1
puts "once.\n\n"
else
puts "#{test_iterations} times.\n\n"
end
test_iterations.times do
Benchmark.bmbm do |x|
(0..5).each do |i|
x.report("process README.md concatenated #{2**i} times with BlueCloth") { BlueCloth::new(@readme_files[i]).to_html }
end
end
puts
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.