Speeding up MouseHole (ATTACHMENT)
why the lucky stiff
why at hobix.com
Sun Sep 4 17:28:53 EDT 2005
why the lucky stiff wrote:
> Okay, I've had some good success speeding things up. I've attached a
> benchmark script I'm playing with. You can take a look at that later.
And here is the script. Happy.
_why
-------------- next part --------------
require './lib/mouseHole'
require 'htree'
require 'xml/smart'
require 'benchmark'
puts Benchmark::CAPTION
Tidy.path = '/usr/lib/libtidy.so'
xml = ""
test_html = "bb.html"
n = 50
Benchmark.bm do |x|
x.report "tidy+rexml:" do
html = File.read( test_html )
n.times do
Tidy.open(:output_xhtml=>true) do |tidy|
xml = REXML::Document.new(tidy.clean html)
end
xml = xml.to_s
end
end
File.open( "tidy+rexml-#{ test_html }", 'w' ) do |f|
f << xml
end
x.report "cached tidy+rexml:" do
html = File.read( "tidy+rexml-#{ test_html }" )
n.times do
xml = REXML::Document.new html
xml = xml.to_s
end
end
x.report "htree+rexml:" do
html = File.read test_html
n.times do
xml = nil
HTree.parse( html ).each_child do |child|
if child.respond_to? :qualified_name
if child.qualified_name == 'html'
xml = HTree::Doc.new( child ).to_rexml
break
end
end
end
xml = xml.to_s
end
end
File.open( "htree+rexml-#{ test_html }", 'w' ) do |f|
f << xml
end
x.report "htree only:" do
html = File.read test_html
n.times do
xml = HTree.parse( html )
end
xml = xml.to_s
end
File.open( "htree-#{ test_html }", 'w' ) do |f|
f << xml
end
x.report "tidy+smart:" do
html = File.read test_html
n.times do
Tidy.open(:output_xhtml=>true) do |tidy|
xml = XML::Smart.string(tidy.clean html)
end
end
end
File.open( "tidy+smart-#{ test_html }", 'w' ) do |f|
f << xml
end
end
More information about the Mousehole-scripters
mailing list