Skip to content

Commit

Permalink
Add/update benchmarks for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Nov 4, 2009
1 parent 9abed91 commit b0d6729
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 14 deletions.
12 changes: 12 additions & 0 deletions benchmarks/concat_vs_join.rb
@@ -0,0 +1,12 @@
require "benchmark"

STR1 = "Hello"
JOIN = "::"
STR2 = "World"

TESTS = 100_000
Benchmark.bmbm do |results|
results.report("concat") { TESTS.times { "".concat(STR1).concat(JOIN).concat(STR2) } }
results.report("add ") { TESTS.times { STR1 + JOIN + STR2 } }
results.report("join ") { TESTS.times { [STR1, STR2].join(JOIN) } }
end
28 changes: 14 additions & 14 deletions benchmarks/erb_vs_erubis.rb
Expand Up @@ -6,46 +6,46 @@
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')

def rungen
YARD::Registry.clear
YARD::CLI::Yardoc.run('--quiet', '--use-cache')
YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
YARD::Registry.at("YARD::CodeObjects::Base").format(:format => :html)
end

Benchmark.bmbm do |x|
x.report("erubis") do
eval <<-eof
class YARD::Generators::Base
def erb(str) Erubis::Eruby.new(str) end
end
module YARD; module Templates; module Template
def erb_with(str, x) Erubis::Eruby.new(str) end
end end end
eof

rungen
end

x.report("fast-erubis") do
eval <<-eof
class YARD::Generators::Base
def erb(str) Erubis::FastEruby.new(str) end
end
module YARD; module Templates; module Template
def erb_with(str, x) Erubis::FastEruby.new(str) end
end end end
eof

rungen
end

x.report("tiny-erubis") do
eval <<-eof
class YARD::Generators::Base
def erb(str) Erubis::TinyEruby.new(str) end
end
module YARD; module Templates; module Template
def erb_with(str, x) Erubis::TinyEruby.new(str) end
end end end
eof

rungen
end

x.report("erb") do
eval <<-eof
class YARD::Generators::Base
def erb(str) ERB.new(str, nil, '<>') end
end
module YARD; module Templates; module Template
def erb_with(str, x) ERB.new(str, nil) end
end end end
eof

rungen
Expand Down
50 changes: 50 additions & 0 deletions benchmarks/pathname_vs_string.rb
@@ -0,0 +1,50 @@
require 'pathname'
require "benchmark"
require File.dirname(__FILE__) + '/../lib/yard'

pathobj = Pathname.new("a/b/c")
strobj = "a/b/c"

TIMES = 1_000

puts "join:"
Benchmark.bmbm do |x|
x.report("pathname") { TIMES.times { Pathname.new("a/b/c").join("d", "e", "f") } }
x.report("string ") { TIMES.times { File.join("a/b/c", "d", "e", "f") } }
x.report("pathname-sameobject") { TIMES.times { pathobj.join("d", "e", "f") } }
x.report("string-sameobject ") { TIMES.times { File.join(strobj, "d", "e", "f") } }
end

puts
puts
puts "cleanpath:"
Benchmark.bmbm do |x|
x.report("pathname") { TIMES.times { Pathname.new("a/b//.././c").cleanpath } }
x.report("string ") { TIMES.times { File.cleanpath("a/b//.././c") } }
end

__END__
join:
Rehearsal -------------------------------------------------------
pathname 0.330000 0.020000 0.350000 ( 0.353481)
string 0.010000 0.000000 0.010000 ( 0.001390)
pathname-sameobject 0.360000 0.020000 0.380000 ( 0.384473)
string-sameobject 0.000000 0.000000 0.000000 ( 0.001187)
---------------------------------------------- total: 0.740000sec

user system total real
pathname 0.330000 0.020000 0.350000 ( 0.350820)
string 0.000000 0.000000 0.000000 ( 0.001055)
pathname-sameobject 0.330000 0.010000 0.340000 ( 0.346949)
string-sameobject 0.000000 0.000000 0.000000 ( 0.001141)


cleanpath:
Rehearsal --------------------------------------------
pathname 0.060000 0.000000 0.060000 ( 0.059767)
string 0.010000 0.000000 0.010000 ( 0.013775)
----------------------------------- total: 0.070000sec

user system total real
pathname 0.060000 0.000000 0.060000 ( 0.059697)
string 0.020000 0.000000 0.020000 ( 0.013624)
22 changes: 22 additions & 0 deletions benchmarks/template_erb.rb
@@ -0,0 +1,22 @@
require "benchmark"
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')

YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
obj = YARD::Registry.at("YARD::CodeObjects::Base")

TIMES = 3
Benchmark.bm do |x|
x.report("trim-line") { TIMES.times { obj.format(:format => :html) } }
module YARD
module Templates
module Template
def erb(section, &block)
erb = ERB.new(cache(section), nil)
erb.filename = cache_filename(section).to_s
erb.result(binding, &block)
end
end
end
end
x.report("no-trim ") { TIMES.times { obj.format(:format => :html) } }
end
6 changes: 6 additions & 0 deletions benchmarks/template_format.rb
@@ -0,0 +1,6 @@
require "benchmark"
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')

YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
obj = YARD::Registry.at("YARD::CodeObjects::Base")
puts Benchmark.measure { obj.format(:format => :html) }
18 changes: 18 additions & 0 deletions benchmarks/template_profile.rb
@@ -0,0 +1,18 @@
require 'rubygems'
#require 'ruby-prof'
#require 'benchmark'
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')

YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
obj = YARD::Registry.at("YARD::CodeObjects::Base")

require 'perftools'
PerfTools::CpuProfiler.start("template_profile") do
obj.format(:format => :html, :no_highlight => true)
end

# result = RubyProf.profile do
# end
#
# printer = RubyProf::CallTreePrinter.new(result)
# printer.print(STDOUT)

0 comments on commit b0d6729

Please sign in to comment.