-
Notifications
You must be signed in to change notification settings - Fork 70
/
parse.yaml
57 lines (52 loc) · 1.44 KB
/
parse.yaml
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
loop_count: 100
contexts:
- gems:
rexml: 3.2.6
require: false
prelude: require 'rexml'
- name: master
prelude: |
$LOAD_PATH.unshift(File.expand_path("lib"))
require 'rexml'
- name: 3.2.6(YJIT)
gems:
rexml: 3.2.6
require: false
prelude: |
require 'rexml'
RubyVM::YJIT.enable
- name: master(YJIT)
prelude: |
$LOAD_PATH.unshift(File.expand_path("lib"))
require 'rexml'
RubyVM::YJIT.enable
prelude: |
require 'rexml/document'
require 'rexml/parsers/sax2parser'
require 'rexml/parsers/pullparser'
require 'rexml/parsers/streamparser'
require 'rexml/streamlistener'
n_elements = Integer(ENV.fetch("N_ELEMENTS", "5000"), 10)
n_attributes = Integer(ENV.fetch("N_ATTRIBUTES", "2"), 10)
def build_xml(n_elements, n_attributes)
xml = '<?xml version="1.0"?><root>'
n_elements.times do |i|
xml << '<child '
n_attributes.times {|j| xml << "id#{j}=\"#{i}\" " }
xml << '/>'
end
xml << '</root>'
end
xml = build_xml(n_elements, n_attributes)
class Listener
include REXML::StreamListener
end
benchmark:
'dom' : REXML::Document.new(xml).elements.each("root/child") {|_|}
'sax' : REXML::Parsers::SAX2Parser.new(xml).parse
'pull' : |
parser = REXML::Parsers::PullParser.new(xml)
while parser.has_next?
parser.pull
end
'stream' : REXML::Parsers::StreamParser.new(xml, Listener.new).parse