ox 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

Files changed (61) hide show
  1. data/README.md +21 -3
  2. data/ext/ox/dump.c +64 -42
  3. data/ext/ox/extconf.rb +34 -2
  4. data/ext/ox/gen_load.c +13 -13
  5. data/ext/ox/obj_load.c +31 -28
  6. data/ext/ox/ox.c +41 -31
  7. data/ext/ox/ox.h +20 -13
  8. data/ext/ox/parse.c +1 -0
  9. data/ext/ox/sax.c +323 -26
  10. data/lib/ox.rb +1 -2
  11. data/lib/ox/element.rb +1 -1
  12. data/lib/ox/sax.rb +24 -11
  13. data/lib/ox/version.rb +1 -1
  14. metadata +4 -50
  15. data/test/Sample.graffle +0 -2318
  16. data/test/bench.rb +0 -53
  17. data/test/bug1.rb +0 -24
  18. data/test/bug2.rb +0 -38
  19. data/test/bug3.rb +0 -21
  20. data/test/cache16_test.rb +0 -17
  21. data/test/cache8_test.rb +0 -17
  22. data/test/cache_test.rb +0 -17
  23. data/test/files.rb +0 -29
  24. data/test/func.rb +0 -652
  25. data/test/gen_sample.rb +0 -22
  26. data/test/obj_sample.rb +0 -19
  27. data/test/ox/change.rb +0 -16
  28. data/test/ox/dir.rb +0 -21
  29. data/test/ox/doc.rb +0 -39
  30. data/test/ox/file.rb +0 -33
  31. data/test/ox/group.rb +0 -18
  32. data/test/ox/hasprops.rb +0 -18
  33. data/test/ox/layer.rb +0 -14
  34. data/test/ox/line.rb +0 -22
  35. data/test/ox/oval.rb +0 -12
  36. data/test/ox/rect.rb +0 -12
  37. data/test/ox/shape.rb +0 -37
  38. data/test/ox/text.rb +0 -23
  39. data/test/parse_cmp.rb +0 -261
  40. data/test/perf.rb +0 -91
  41. data/test/perf_gen.rb +0 -237
  42. data/test/perf_mars.rb +0 -114
  43. data/test/perf_obj.rb +0 -124
  44. data/test/perf_pod.rb +0 -88
  45. data/test/perf_sax.rb +0 -233
  46. data/test/perf_write.rb +0 -80
  47. data/test/sample.rb +0 -55
  48. data/test/sample/change.rb +0 -14
  49. data/test/sample/dir.rb +0 -19
  50. data/test/sample/doc.rb +0 -36
  51. data/test/sample/file.rb +0 -48
  52. data/test/sample/group.rb +0 -16
  53. data/test/sample/hasprops.rb +0 -16
  54. data/test/sample/layer.rb +0 -12
  55. data/test/sample/line.rb +0 -20
  56. data/test/sample/oval.rb +0 -10
  57. data/test/sample/rect.rb +0 -10
  58. data/test/sample/shape.rb +0 -35
  59. data/test/sample/text.rb +0 -20
  60. data/test/sax_test.rb +0 -468
  61. data/test/test.rb +0 -70
data/test/perf.rb DELETED
@@ -1,91 +0,0 @@
1
-
2
- class Perf
3
-
4
- def initialize()
5
- @items = []
6
- end
7
-
8
- def add(title, op, &blk)
9
- @items << Item.new(title, op, &blk)
10
- end
11
-
12
- def run(iter)
13
- base = Item.new(nil, nil) { }
14
- base.run(iter, 0.0)
15
- @items.each do |i|
16
- i.run(iter, base.duration)
17
- if i.error.nil?
18
- puts "#{i.title}.#{i.op} #{iter} times in %0.3f seconds or %0.3f #{i.op}/sec." % [i.duration, iter / i.duration]
19
- else
20
- puts "***** #{i.title}.#{i.op} failed! #{i.error}"
21
- end
22
- end
23
- summary()
24
- end
25
-
26
- def summary()
27
- fastest = nil
28
- slowest = nil
29
- width = 6
30
- @items.each do |i|
31
- next if i.duration.nil?
32
- width = i.title.size if width < i.title.size
33
- end
34
- iva = @items.clone
35
- iva.delete_if { |i| i.duration.nil? }
36
- iva.sort_by! { |i| i.duration }
37
- puts
38
- puts "Summary:"
39
- puts "%*s time (secs) rate (ops/sec)" % [width, 'System']
40
- puts "#{'-' * width} ----------- --------------"
41
- iva.each do |i|
42
- if i.duration.nil?
43
- else
44
- puts "%*s %11.3f %14.3f" % [width, i.title, i.duration, i.rate ]
45
- end
46
- end
47
- puts
48
- puts "Comparison Matrix\n(performance factor, 2.0 means row is twice as fast as column)"
49
- puts ([' ' * width] + iva.map { |i| "%*s" % [width, i.title] }).join(' ')
50
- puts (['-' * width] + iva.map { |i| '-' * width }).join(' ')
51
- iva.each do |i|
52
- line = ["%*s" % [width, i.title]]
53
- iva.each do |o|
54
- line << "%*.2f" % [width, o.duration / i.duration]
55
- end
56
- puts line.join(' ')
57
- end
58
- puts
59
- end
60
-
61
- class Item
62
- attr_accessor :title
63
- attr_accessor :op
64
- attr_accessor :blk
65
- attr_accessor :duration
66
- attr_accessor :rate
67
- attr_accessor :error
68
-
69
- def initialize(title, op, &blk)
70
- @title = title
71
- @blk = blk
72
- @op = op
73
- @duration = nil
74
- @rate = nil
75
- @error = nil
76
- end
77
-
78
- def run(iter, base)
79
- begin
80
- start = Time.now
81
- iter.times { @blk.call }
82
- @duration = Time.now - start - base
83
- @duration = 0.0 if @duration < 0.0
84
- @rate = iter / @duration
85
- rescue Exception => e
86
- @error = "#{e.class}: #{e.message}"
87
- end
88
- end
89
-
90
- end # Item
91
- end # Perf
data/test/perf_gen.rb DELETED
@@ -1,237 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '.'
4
- $: << '..'
5
- $: << '../lib'
6
- $: << '../ext'
7
-
8
- if __FILE__ == $0
9
- if (i = ARGV.index('-I'))
10
- x,path = ARGV.slice!(i, 2)
11
- $: << path
12
- end
13
- end
14
-
15
- require 'optparse'
16
- require 'ox'
17
- require 'sample'
18
- require 'test/ox/doc'
19
- require 'files'
20
- begin
21
- require 'nokogiri'
22
- rescue Exception => e
23
- end
24
- begin
25
- require 'libxml'
26
- rescue Exception => e
27
- end
28
-
29
- $verbose = 0
30
- $ox_only = false
31
-
32
- do_sample = false
33
- do_files = false
34
-
35
- do_load = false
36
- do_dump = false
37
- do_read = false
38
- do_write = false
39
- $iter = 1000
40
-
41
- opts = OptionParser.new
42
- opts.on("-v", "increase verbosity") { $verbose += 1 }
43
-
44
- opts.on("-x", "ox only") { $ox_only = true }
45
-
46
- opts.on("-s", "load and dump as sample Ruby object") { do_sample = true }
47
- opts.on("-f", "load and dump as files Ruby object") { do_files = true }
48
-
49
- opts.on("-l", "load") { do_load = true }
50
- opts.on("-d", "dump") { do_dump = true }
51
- opts.on("-r", "read") { do_read = true }
52
- opts.on("-w", "write") { do_write = true }
53
- opts.on("-a", "load, dump, read and write") { do_load = true; do_dump = true; do_read = true; do_write = true }
54
-
55
- opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| $iter = i }
56
-
57
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
58
- files = opts.parse(ARGV)
59
-
60
- if files.empty?
61
- data = []
62
- obj = do_sample ? sample_doc(2) : files('..')
63
- xml = Ox.dump(obj, :indent => 2, :opt_format => true)
64
- File.open('sample.xml', 'w') { |f| f.write(xml) }
65
- gen = Ox.parse(xml)
66
- h = { :file => 'sample.xml', :xml => xml, :ox => gen }
67
- h[:nokogiri] = Nokogiri::XML::Document.parse(xml) unless defined?(::Nokogiri).nil?
68
- h[:libxml] = LibXML::XML::Document.string(xml) unless defined?(::LibXML).nil?
69
- data << h
70
- else
71
- puts "loading and parsing #{files}\n\n"
72
- data = files.map do |f|
73
- xml = File.read(f)
74
- obj = Ox.parse(xml);
75
- gen = Ox.parse(xml)
76
- h = { :file => f, :xml => xml, :ox => gen }
77
- h[:nokogiri] = Nokogiri::XML::Document.parse(xml) unless defined?(::Nokogiri).nil?
78
- h[:libxml] = LibXML::XML::Document.string(xml) unless defined?(::LibXML).nil?
79
- h
80
- end
81
- end
82
-
83
- $ox_load_time = 0
84
- $no_load_time = 0
85
- $lx_load_time = 0
86
- $ox_dump_time = 0
87
- $no_dump_time = 0
88
- $lx_dump_time = 0
89
-
90
- def perf_load(d)
91
- xml = d[:xml]
92
-
93
- if 0 < $verbose
94
- obj = Ox.load(xml, :mode => :generic, :trace => $verbose)
95
- return
96
- end
97
- start = Time.now
98
- (1..$iter).each do
99
- #obj = Ox.load(xml, :mode => :generic)
100
- obj = Ox.parse(xml)
101
- end
102
- $ox_load_time = Time.now - start
103
- puts "Parsing #{$iter} times with Ox took #{$ox_load_time} seconds."
104
-
105
- return if $ox_only
106
-
107
- unless defined?(::Nokogiri).nil?
108
- start = Time.now
109
- (1..$iter).each do
110
- obj = Nokogiri::XML::Document.parse(xml)
111
- #obj = Nokogiri::XML::Document.parse(xml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS)
112
- end
113
- $no_load_time = Time.now - start
114
- puts "Nokogiri parse #{$iter} times took #{$no_load_time} seconds."
115
- end
116
-
117
- unless defined?(::LibXML).nil?
118
- start = Time.now
119
- (1..$iter).each do
120
- obj = LibXML::XML::Document.string(xml)
121
- end
122
- $lx_load_time = Time.now - start
123
- puts "LibXML parse #{$iter} times took #{$lx_load_time} seconds."
124
- end
125
- puts "\n"
126
- puts ">>> Ox is %0.1f faster than Nokogiri parsing." % [$no_load_time/$ox_load_time] unless defined?(::Nokogiri).nil?
127
- puts ">>> Ox is %0.1f faster than LibXML parsing." % [$lx_load_time/$ox_load_time] unless defined?(::LibXML).nil?
128
- puts "\n"
129
- end
130
-
131
- def perf_dump(d)
132
- obj = d[:ox]
133
-
134
- start = Time.now
135
- (1..$iter).each do
136
- xml = Ox.dump(obj, :indent => 2)
137
- # puts "*** ox:\n#{xml}"
138
- end
139
- $ox_dump_time = Time.now - start
140
- puts "Ox dumping #{$iter} times with ox took #{$ox_dump_time} seconds."
141
-
142
- return if $ox_only
143
-
144
- unless defined?(::Nokogiri).nil?
145
- obj = d[:nokogiri]
146
- start = Time.now
147
- (1..$iter).each do
148
- xml = obj.to_xml(:indent => 2)
149
- end
150
- $no_dump_time = Time.now - start
151
- puts "Nokogiri to_xml #{$iter} times took #{$no_dump_time} seconds."
152
- end
153
-
154
- unless defined?(::LibXML).nil?
155
- obj = d[:libxml]
156
- start = Time.now
157
- (1..$iter).each do
158
- xml = obj.to_s()
159
- end
160
- $lx_dump_time = Time.now - start
161
- puts "LibML to_s #{$iter} times took #{$lx_dump_time} seconds."
162
- end
163
- puts "\n"
164
- puts ">>> Ox is %0.1f faster than Nokkgiri to_xml." % [$no_dump_time/$ox_dump_time] unless defined?(::Nokogiri).nil?
165
- puts ">>> Ox is %0.1f faster than LibXML to_xml." % [$lx_dump_time/$ox_dump_time] unless defined?(::LibXML).nil?
166
- puts "\n"
167
- end
168
-
169
- def perf_read(d)
170
- ox_read_time = 0
171
-
172
- filename = d[:file]
173
-
174
- # now load from the file
175
- start = Time.now
176
- (1..$iter).each do
177
- obj = Ox.load_file(filename, :mode => :generic)
178
- end
179
- ox_read_time = Time.now - start
180
- puts "Loading and parsing #{$iter} times with ox took #{ox_read_time} seconds."
181
-
182
- return if $ox_only
183
-
184
- unless defined?(::Nokogiri).nil?
185
- start = Time.now
186
- (1..$iter).each do
187
- xml = File.read(filename)
188
- obj = Nokogiri::XML::Document.parse(xml)
189
- end
190
- no_read_time = Time.now - start
191
- puts "Reading and parsing #{$iter} times took #{no_read_time} seconds."
192
- puts ">>> Ox is %0.1f faster than Nokogiri loading and parsing.\n\n" % [no_read_time/ox_read_time]
193
- end
194
- end
195
-
196
- def perf_write(d)
197
- ox_write_time = 0
198
-
199
- filename = 'out.xml'
200
- no = 'out.xml'
201
- obj = d[:ox]
202
-
203
- start = Time.now
204
- (1..$iter).each do
205
- xml = Ox.to_file(filename, obj, :indent => 0)
206
- end
207
- ox_write_time = Time.now - start
208
- puts "Ox dumping #{$iter} times with ox took #{ox_write_time} seconds."
209
-
210
- return if $ox_only
211
-
212
- unless defined?(::Nokogiri).nil?
213
- obj = d[:nokogiri]
214
- start = Time.now
215
- (1..$iter).each do
216
- xml = obj.to_xml(:indent => 0)
217
- File.open(filename, "w") { |f| f.write(xml) }
218
- end
219
- no_write_time = Time.now - start
220
- puts "Nokogiri dumping and writing #{$iter} times took #{no_write_time} seconds."
221
- puts ">>> Ox is %0.1f faster than Nokogiri writing.\n\n" % [no_write_time/ox_write_time]
222
- end
223
- end
224
-
225
- data.each do |d|
226
- puts "Using file #{d[:file]}."
227
-
228
- perf_load(d) if do_load
229
- perf_dump(d) if do_dump
230
- if do_load and do_dump
231
- puts ">>> Ox is %0.1f faster than Nokogiri dumping and loading.\n\n" % [($no_load_time + $no_dump_time)/($ox_load_time + $ox_dump_time)] unless 0 == $no_load_time
232
- end
233
-
234
- perf_read(d) if do_read
235
- perf_write(d) if do_write
236
-
237
- end
data/test/perf_mars.rb DELETED
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '.'
4
- $: << '..'
5
- $: << '../lib'
6
- $: << '../ext'
7
-
8
- if __FILE__ == $0
9
- if (i = ARGV.index('-I'))
10
- x,path = ARGV.slice!(i, 2)
11
- $: << path
12
- end
13
- end
14
-
15
- require 'optparse'
16
- require 'pp'
17
- require 'ox'
18
-
19
- it = 5000
20
-
21
- opts = OptionParser.new
22
- opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| it = i }
23
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
24
- files = opts.parse(ARGV)
25
-
26
- module Test
27
- module Ox
28
- class Wrap
29
- attr_accessor :values
30
- def initialize(v=[])
31
- @values = v
32
- end
33
- end
34
- end
35
- end
36
-
37
- data = {
38
- :Boolean => ::Test::Ox::Wrap.new(),
39
- :Fixnum => ::Test::Ox::Wrap.new(),
40
- :Float => ::Test::Ox::Wrap.new(),
41
- :String => ::Test::Ox::Wrap.new(),
42
- :Symbol => ::Test::Ox::Wrap.new(),
43
- :Time => ::Test::Ox::Wrap.new(),
44
- :Array => ::Test::Ox::Wrap.new(),
45
- :Hash => ::Test::Ox::Wrap.new(),
46
- :Range => ::Test::Ox::Wrap.new(),
47
- :Regexp => ::Test::Ox::Wrap.new(),
48
- :Bignum => ::Test::Ox::Wrap.new(),
49
- :Complex => ::Test::Ox::Wrap.new(),
50
- :Rational => ::Test::Ox::Wrap.new(),
51
- :Struct => ::Test::Ox::Wrap.new(),
52
- :Class => ::Test::Ox::Wrap.new(),
53
- :Object => ::Test::Ox::Wrap.new(),
54
- }
55
-
56
- s = Struct.new('Zoo', :x, :y, :z)
57
-
58
- (1..200).each do |i|
59
- data[:Boolean].values << (0 == (i % 2))
60
- data[:Fixnum].values << ((i - 10) * 101)
61
- data[:Float].values << ((i.to_f - 10.7) * 30.5)
62
- data[:String].values << "String #{i}"
63
- data[:Symbol].values << "Symbol#{i}".to_sym
64
- data[:Time].values << Time.now + i
65
- data[:Array].values << []
66
- data[:Hash].values << { }
67
- data[:Range].values << (0..7)
68
- data[:Regexp].values << /^[0-9]/
69
- data[:Bignum].values << (7 ** 55)
70
- data[:Complex].values << Complex(1, 2)
71
- data[:Rational].values << Rational(1, 3)
72
- data[:Struct].values << s.new(1, 3, 5)
73
- data[:Class].values << ::Test::Ox::Wrap
74
- data[:Object].values << ::Test::Ox::Wrap.new(i)
75
- end
76
-
77
- puts " load dump"
78
- puts "type Ox Marshal ratio Ox Marshal ratio"
79
- data.each do |type,a|
80
- #xml = Ox.dump(a, :indent => -1, :xsd_date => true)
81
- xml = Ox.dump(a, :indent => -1)
82
- #pp a
83
- #puts xml
84
- start = Time.now
85
- (1..it).each do
86
- obj = Ox.load(xml, :mode => :object)
87
- #pp obj
88
- end
89
- ox_load_time = Time.now - start
90
-
91
- m = Marshal.dump(a)
92
- start = Time.now
93
- (1..it).each do
94
- obj = Marshal.load(m)
95
- end
96
- mars_load_time = Time.now - start
97
-
98
- obj = Ox.load(xml, :mode => :object)
99
- start = Time.now
100
- (1..it).each do
101
- xml = Ox.dump(a, :indent => -1)
102
- end
103
- ox_dump_time = Time.now - start
104
-
105
- start = Time.now
106
- (1..it).each do
107
- m = Marshal.dump(a)
108
- end
109
- mars_dump_time = Time.now - start
110
-
111
- puts "%8s %6.3f %6.3f %0.1f %6.3f %6.3f %0.1f" % [type.to_s,
112
- ox_load_time, mars_load_time, mars_load_time / ox_load_time,
113
- ox_dump_time, mars_dump_time, mars_dump_time / ox_dump_time]
114
- end
data/test/perf_obj.rb DELETED
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '.'
4
- $: << '../lib'
5
- $: << '../ext'
6
-
7
- if __FILE__ == $0
8
- if (i = ARGV.index('-I'))
9
- x,path = ARGV.slice!(i, 2)
10
- $: << path
11
- end
12
- end
13
-
14
- require 'optparse'
15
- require 'ox'
16
- require 'oj'
17
- require 'perf'
18
- require 'sample'
19
- require 'files'
20
-
21
- $circular = false
22
- $indent = 0
23
-
24
- do_sample = false
25
- do_files = false
26
-
27
- do_load = false
28
- do_dump = false
29
- do_read = false
30
- do_write = false
31
- $iter = 1000
32
-
33
- opts = OptionParser.new
34
- opts.on("-c", "circular options") { $circular = true }
35
-
36
- opts.on("-s", "load and dump as sample Ruby object") { do_sample = true }
37
- opts.on("-f", "load and dump as files Ruby object") { do_files = true }
38
-
39
- opts.on("-l", "load") { do_load = true }
40
- opts.on("-d", "dump") { do_dump = true }
41
- opts.on("-r", "read") { do_read = true }
42
- opts.on("-w", "write") { do_write = true }
43
- opts.on("-a", "load, dump, read and write") { do_load = true; do_dump = true; do_read = true; do_write = true }
44
-
45
- opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| $iter = i }
46
-
47
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
48
- files = opts.parse(ARGV)
49
-
50
- $obj = nil
51
- $xml = nil
52
- $mars = nil
53
- $json = nil
54
-
55
- unless do_load || do_dump || do_read || do_write
56
- do_load = true
57
- do_dump = true
58
- do_read = true
59
- do_write = true
60
- end
61
-
62
- # prepare all the formats for input
63
- if files.empty?
64
- $obj = do_sample ? sample_doc(2) : files('..')
65
- $mars = Marshal.dump($obj)
66
- $xml = Ox.dump($obj, :indent => $indent, circular: $circular)
67
- $json = Oj.dump($obj, :indent => $indent, circular: $circular)
68
- File.open('sample.xml', 'w') { |f| f.write($xml) }
69
- File.open('sample.json', 'w') { |f| f.write($json) }
70
- File.open('sample.marshal', 'w') { |f| f.write($mars) }
71
- else
72
- puts "loading and parsing #{files}\n\n"
73
- # TBD change to allow xml and json
74
- data = files.map do |f|
75
- $xml = File.read(f)
76
- $obj = Ox.load($xml);
77
- $mars = Marshal.dump($obj)
78
- $json = Oj.dump($obj, :indent => $indent, circular: $circular)
79
- end
80
- end
81
-
82
- Oj.default_options = { :mode => :object, :indent => $indent }
83
-
84
- if do_load
85
- puts '-' * 80
86
- puts "Load Performance"
87
- perf = Perf.new()
88
- perf.add('Ox', 'load') { Ox.load($xml, :mode => :object) }
89
- perf.add('Oj', 'load') { Oj.load($json) }
90
- perf.add('Marshal', 'load') { Marshal.load($mars) }
91
- perf.run($iter)
92
- end
93
-
94
- if do_dump
95
- puts '-' * 80
96
- puts "Dump Performance"
97
- perf = Perf.new()
98
- perf.add('Ox', 'dump') { Ox.dump($obj, :indent => $indent, :circular => $circular) }
99
- perf.add('Oj', 'dump') { Oj.dump($obj) }
100
- perf.add('Marshal', 'dump') { Marshal.dump($obj) }
101
- perf.run($iter)
102
- end
103
-
104
- if do_read
105
- puts '-' * 80
106
- puts "Read from file Performance"
107
- perf = Perf.new()
108
- perf.add('Ox', 'load_file') { Ox.load_file('sample.xml', :mode => :object) }
109
- perf.add('Oj', 'load') { Oj.load_file('sample.json') }
110
- perf.add('Marshal', 'load') { Marshal.load(File.new('sample.marshal')) }
111
- perf.run($iter)
112
- end
113
-
114
- if do_write
115
- puts '-' * 80
116
- puts "Write to file Performance"
117
- perf = Perf.new()
118
- perf.add('Ox', 'to_file') { Ox.to_file('sample.xml', $obj, :indent => $indent, :circular => $circular) }
119
- perf.add('Oj', 'to_file') { Oj.to_file('sample.json', $obj) }
120
- perf.add('Marshal', 'dump') { Marshal.dump($obj, File.new('sample.marshal', 'w')) }
121
- perf.run($iter)
122
- end
123
-
124
-