-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
57 lines (51 loc) · 1.03 KB
/
Rakefile
File metadata and controls
57 lines (51 loc) · 1.03 KB
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
require 'benchmark'
require 'nokogiri'
require './lib/html-tag'
def ng_tag &block
builder = Nokogiri::XML::DocumentFragment.parse("")
Nokogiri::XML::Builder.with( builder, &block )
builder.to_html
end
def measure name
out = nil
puts name
puts Benchmark.measure {
10_000.times do
out = yield
end
}
puts out
puts
end
###
desc 'Speed test (x10_000)'
task :speed do
measure 'Nokogiri::XML::Builder' do
ng_tag do |doc|
doc.div do
doc.send('foo-bar') { doc.text 123 }
doc.div.foo(onload: 'some_func();') do
doc.span.bold do
doc.text "Hello world"
end
end
end
end
end
measure 'HtmlTag slim' do
HtmlTag :div do
tag('foo-bar', 123)
_foo(onload: 'some_func();') do
span(class: :bold) { "Hello world" }
end
end
end
measure 'HtmlTag safe' do
HtmlTag.div do |n|
n.tag('foo-bar', 123)
n._foo(onload: 'some_func();') do |n|
n.span(class: :bold) { "Hello world" }
end
end
end
end