madx (owner)

Revisions

gist: 127889 Download_button fork
public
Public Clone URL: git://gist.github.com/127889.git
Embed All Files: show embed
bench.rb #
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
require 'rubygems'
require File.join(File.dirname(__FILE__), 'lib', 'xup')
require 'redcloth'
require 'haml'
require 'markaby'
require 'benchmark'
 
Xup.load :xml
 
n = 10_000
Benchmark.bm(10) do |x|
  x.report("xup:") do
    for i in 0..n
      xc = Xup::Context.new
      xc.instance_eval {
        use :XML
        tag! :para, "foo"
        tag! :ul do
          tag! :li, 'one'
          tag! :li, 'two'
          tag! :li, 'three'
        end
      }
      xc.buffer
    end
  end
 
  x.report("xup (str):") do
    for i in 0..n
      xc = Xup::Context.new
      xc.instance_eval &lambda { eval <<-eof
use :XML
tag! :para, "foo"
tag! :ul do
tag! :li, 'one'
tag! :li, 'two'
tag! :li, 'three'
end
eof
      }
      xc.buffer
    end
  end
 
  x.report("markaby:") do
    for i in 0..n
      Markaby::Builder.new {
        p "foo"
        ul {
          li "one"
          li "two"
          li "three"
        }
      }.streams.first.first
    end
  end
 
  x.report("textile:") do
    for i in 0..n
      RedCloth.new("p. foo\n\n* one\n* two\n* three").to_html
    end
  end
 
  x.report("haml:") do
    for i in 0..n
      Haml::Engine.new("%p foo\n%ul\n %li one\n %li two\n %li three").to_html
    end
  end
end
 
results.txt #
1
2
3
4
5
6
7
                user system total real
xup: 1.990000 0.050000 2.040000 ( 2.108340)
xup (str): 2.440000 0.090000 2.530000 ( 2.538592)
markaby: 8.680000 0.220000 8.900000 ( 8.992089)
textile: 9.000000 0.880000 9.880000 ( 9.989805)
haml: 8.770000 0.350000 9.120000 ( 9.237272)