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_pod.rb DELETED
@@ -1,88 +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 'pod/cfg'
18
- require 'pod/xml'
19
-
20
- $verbose = 0
21
- $use_opt_format = false
22
-
23
- do_load = false
24
- do_dump = false
25
-
26
- opts = OptionParser.new
27
- opts.on("-v", "increase verbosity") { $verbose += 1 }
28
- opts.on("-o", "optimized format") { $use_opt_format = true }
29
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
30
- files = opts.parse(ARGV)
31
-
32
-
33
- $ox_load_time = 0
34
- $opt_load_time = 0
35
- $no_load_time = 0
36
- $ox_dump_time = 0
37
- $no_dump_time = 0
38
-
39
- files = Dir.glob('data/**/*.xml')
40
- xml_data = files.map { |f| File.read(f) }
41
-
42
- objs = []
43
- start = Time.now
44
- xml_data.each do |xml|
45
- objs << Ox.load(xml, :mode => :object, :trace => 0)
46
- end
47
- $ox_load_time = Time.now - start
48
- puts "Loading #{files.size} files with Ox took #{$ox_load_time} seconds."
49
-
50
- start = Time.now
51
- objs.each do |o|
52
- xml = Ox.dump(o, :opt_format => $use_opt_format, :indent => 0)
53
- end
54
- $ox_dump_time = Time.now - start
55
- puts "Dumping #{files.size} files with Ox took #{$ox_dump_time} seconds."
56
-
57
-
58
- opt_data = objs.map { |o| Ox.dump(o, :opt_format => $use_opt_format, :indent => 0) }
59
- mode = $use_opt_format ? :optimized : :object
60
- objs = []
61
- start = Time.now
62
- opt_data.each do |xml|
63
- objs << Ox.load(xml, :mode => mode, :trace => 0)
64
- end
65
- $opt_load_time = Time.now - start
66
- puts "Loading #{files.size} files with Optimized Ox took #{$opt_load_time} seconds.\n\n"
67
-
68
-
69
- objs = []
70
- start = Time.now
71
- xml_data.each do |xml|
72
- objs << ::Pod::Xml.to_obj(xml)
73
- end
74
- $no_load_time = Time.now - start
75
- puts "Loading Pod::Xml #{files.size} files took #{$no_load_time} seconds."
76
-
77
- start = Time.now
78
- objs.each do |o|
79
- xml = ::Pod::Xml.to_xml(o)
80
- end
81
- $no_dump_time = Time.now - start
82
- puts "Dumping #{files.size} files with Pod::Xml took #{$no_dump_time} seconds.\n\n"
83
-
84
- puts ">>> Ox is %0.1f faster than Pod::Xml loading." % [$no_load_time/$ox_load_time]
85
- puts ">>> Optimized Ox is %0.1f faster than Pod::Xml loading." % [$no_load_time/$opt_load_time]
86
- puts ">>> Ox is %0.1f faster than Pod::Xml dumping.\n\n" % [$no_dump_time/$ox_dump_time]
87
-
88
- puts ">>> Ox is %0.1f faster than Pod::Xml dumping and loading." % [($no_dump_time + $no_load_time)/($ox_dump_time + $opt_load_time)]
data/test/perf_sax.rb DELETED
@@ -1,233 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '.'
4
- $: << '..'
5
- $: << '../lib'
6
- $: << '../ext'
7
-
8
- if __FILE__ == $0
9
- while (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 'files'
18
- begin
19
- require 'nokogiri'
20
- rescue Exception => e
21
- end
22
- begin
23
- require 'libxml'
24
- rescue Exception => e
25
- end
26
-
27
- $verbose = 0
28
- $ox_only = false
29
- $all_cbs = false
30
- $filename = nil # nil indicates new file names perf.xml will be created and used
31
- $filesize = 1000 # KBytes
32
- $iter = 100
33
-
34
- opts = OptionParser.new
35
- opts.on("-v", "increase verbosity") { $verbose += 1 }
36
- opts.on("-x", "ox only") { $ox_only = true }
37
- opts.on("-a", "all callbacks") { $all_cbs = true }
38
- opts.on("-f", "--file [String]", String, "filename") { |f| $filename = f }
39
- opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| $iter = i }
40
- opts.on("-s", "--size [Int]", Integer, "file size in KBytes") { |s| $filesize = s }
41
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
42
- rest = opts.parse(ARGV)
43
-
44
- $xml_str = nil
45
- $ox_time = 0
46
- $no_time = 0
47
- $lx_time = 0
48
-
49
- # size is in Kbytes
50
- def create_file(filename, size)
51
- head = %{<?xml version="1.0"?>
52
- <?ox version="1.0" mode="object" circular="no" xsd_date="no"?>
53
- <!DOCTYPE table PUBLIC "-//ox//DTD TABLE 1.0//EN" "http://www.ohler.com/DTDs/TestTable-1.0.dtd">
54
- <table>
55
- }
56
- tail = %{</table>
57
- }
58
- row = %{ <!-- row %08d element -->
59
- <row id="%08d">
60
- <cell id="A" type="Fixnum">1234</cell>
61
- <cell id="B" type="String">A string.</cell>
62
- <cell id="C" type="String">This is a longer string that stretches over a larger number of characters.</cell>
63
- <cell id="D" type="Float">-12.345</cell>
64
- <cell id="E" type="Date">2011-09-18 23:07:26 +0900</cell>
65
- <cell id="F" type="Image"><![CDATA[xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00]]></cell>
66
- </row>
67
- }
68
- cnt = (size * 1000 - head.size - tail.size) / row.size
69
- File.open(filename, "w") do |f|
70
- f.write(head)
71
- cnt.times do |i|
72
- f.write(row % [i,i])
73
- end
74
- f.write(tail)
75
- end
76
- end
77
-
78
- class OxSax < ::Ox::Sax
79
- def error(message, line, column); puts message; end
80
- end
81
-
82
- class OxAllSax < OxSax
83
- def start_element(name); end
84
- def attr(name, value); end
85
- def end_element(name); end
86
- def text(value); end
87
- def instruct(target); end
88
- def doctype(value); end
89
- def comment(value); end
90
- def cdata(value); end
91
- end
92
-
93
- unless defined?(::Nokogiri).nil?
94
- class NoSax < Nokogiri::XML::SAX::Document
95
- def error(message); puts message; end
96
- def warning(message); puts message; end
97
- end
98
- class NoAllSax < NoSax
99
- def start_element(name, attrs = []); end
100
- def characters(text); end
101
- def cdata_block(string); end
102
- def comment(string); end
103
- def end_document(); end
104
- def end_element(name); end
105
- def start_document(); end
106
- def xmldecl(version, encoding, standalone); end
107
- end
108
- end
109
-
110
- unless defined?(::LibXML).nil?
111
- class LxSax
112
- include LibXML::XML::SaxParser::Callbacks
113
- end
114
- class LxAllSax < LxSax
115
- def on_start_element(element, attributes); end
116
- def on_cdata_block(cdata); end
117
- def on_characters(chars); end
118
- def on_comment(msg); end
119
- def on_end_document(); end
120
- def on_end_element(element); end
121
- def on_end_element_ns(name, prefix, uri); end
122
- def on_error(msg); end
123
- def on_external_subset(name, external_id, system_id); end
124
- def on_has_external_subset(); end
125
- def on_has_internal_subset(); end
126
- def on_internal_subset(name, external_id, system_id); end
127
- def on_is_standalone(); end
128
- def on_processing_instruction(target, data); end
129
- def on_reference(name); end
130
- def on_start_document(); end
131
- def on_start_element_ns(name, attributes, prefix, uri, namespaces); end
132
- end
133
- end
134
-
135
- def perf_stringio()
136
- start = Time.now
137
- handler = $all_cbs ? OxAllSax.new() : OxSax.new()
138
- $iter.times do
139
- input = StringIO.new($xml_str)
140
- Ox.sax_parse(handler, input)
141
- input.close
142
- end
143
- $ox_time = Time.now - start
144
- puts "StringIO SAX parsing #{$iter} times with Ox took #{$ox_time} seconds."
145
-
146
- return if $ox_only
147
-
148
- unless defined?(::Nokogiri).nil?
149
- handler = Nokogiri::XML::SAX::Parser.new($all_cbs ? NoAllSax.new() : NoSax.new())
150
- start = Time.now
151
- $iter.times do
152
- input = StringIO.new($xml_str)
153
- handler.parse(input)
154
- input.close
155
- end
156
- $no_time = Time.now - start
157
- puts "StringIO SAX parsing #{$iter} times with Nokogiri took #{$no_time} seconds."
158
- end
159
-
160
- unless defined?(::LibXML).nil?
161
- start = Time.now
162
- $iter.times do
163
- input = StringIO.new($xml_str)
164
- parser = LibXML::XML::SaxParser.io(input)
165
- parser.callbacks = $all_cbs ? LxAllSax.new() : LxSax.new()
166
- parser.parse
167
- input.close
168
- end
169
- $lx_time = Time.now - start
170
- puts "StringIO SAX parsing #{$iter} times with LibXML took #{$lx_time} seconds."
171
- end
172
-
173
- puts "\n"
174
- puts ">>> Ox is %0.1f faster than Nokogiri SAX parsing using StringIO." % [$no_time/$ox_time] unless defined?(::Nokogiri).nil?
175
- puts ">>> Ox is %0.1f faster than LibXML SAX parsing using StringIO." % [$lx_time/$ox_time] unless defined?(::LibXML).nil?
176
- puts "\n"
177
- end
178
-
179
- def perf_fileio()
180
- puts "\n"
181
- puts "A #{$filesize} KByte XML file was parsed #{$iter} times for this test."
182
- puts "\n"
183
- start = Time.now
184
- handler = $all_cbs ? OxAllSax.new() : OxSax.new()
185
- $iter.times do
186
- input = IO.open(IO.sysopen($filename))
187
- Ox.sax_parse(handler, input)
188
- input.close
189
- end
190
- $ox_time = Time.now - start
191
- puts "File IO SAX parsing #{$iter} times with Ox took #{$ox_time} seconds."
192
-
193
- return if $ox_only
194
-
195
- unless defined?(::Nokogiri).nil?
196
- handler = Nokogiri::XML::SAX::Parser.new($all_cbs ? NoAllSax.new() : NoSax.new())
197
- start = Time.now
198
- $iter.times do
199
- input = IO.open(IO.sysopen($filename))
200
- handler.parse(input)
201
- input.close
202
- end
203
- $no_time = Time.now - start
204
- puts "File IO SAX parsing #{$iter} times with Nokogiri took #{$no_time} seconds."
205
- end
206
-
207
- unless defined?(::LibXML).nil?
208
- start = Time.now
209
- $iter.times do
210
- input = IO.open(IO.sysopen($filename))
211
- parser = LibXML::XML::SaxParser.io(input)
212
- parser.callbacks = $all_cbs ? LxAllSax.new() : LxSax.new()
213
- parser.parse
214
- input.close
215
- end
216
- $lx_time = Time.now - start
217
- puts "File IO SAX parsing #{$iter} times with LibXML took #{$lx_time} seconds."
218
- end
219
-
220
- puts "\n"
221
- puts ">>> Ox is %0.1f faster than Nokogiri SAX parsing using file IO." % [$no_time/$ox_time] unless defined?(::Nokogiri).nil?
222
- puts ">>> Ox is %0.1f faster than LibXML SAX parsing using file IO." % [$lx_time/$ox_time] unless defined?(::LibXML).nil?
223
- puts "\n"
224
- end
225
-
226
- if $filename.nil?
227
- create_file('perf.xml', $filesize)
228
- $filename = 'perf.xml'
229
- end
230
- $xml_str = File.read($filename)
231
-
232
- # perf_stringio()
233
- perf_fileio()
data/test/perf_write.rb DELETED
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '.'
4
-
5
- if __FILE__ == $0
6
- if (i = ARGV.index('-I'))
7
- x,path = ARGV.slice!(i, 2)
8
- $: << path
9
- end
10
- end
11
-
12
- require 'optparse'
13
- require 'pp'
14
- require 'nokogiri'
15
- require 'ox'
16
-
17
- ox_only = false
18
- it = 1000
19
-
20
- opts = OptionParser.new
21
- opts.on("-x", "ox only") { ox_only = true }
22
- opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| it = i }
23
- opts.on("-h", "--help", "Show this display") { puts opts }
24
- files = opts.parse(ARGV)
25
-
26
- obj = nil
27
-
28
- puts "to String and writing #{files}\n\n"
29
-
30
- data = files.map do |f|
31
- ox_obj = Ox.parse_file(f)
32
- xml = File.read(f)
33
- no_obj = Nokogiri::XML::Document.parse(xml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS)
34
- [f, ox_obj, no_obj]
35
- end
36
-
37
- start = Time.now
38
- data.each do |d|
39
- (1..it).each do
40
- xml = d[1].to_s
41
- end
42
- end
43
- ox_time = Time.now - start
44
- puts "to String #{it} times with ox took #{ox_time} seconds."
45
-
46
- #puts obj.to_s
47
-
48
- =begin
49
- start = Time.now
50
- data.each do |d|
51
- (1..it).each do
52
- xml = d[1].to_s
53
- end
54
- end
55
- ox_time = Time.now - start
56
- puts "to file #{it} times with ox took #{ox_time} seconds.\n\n"
57
- =end
58
- if !ox_only
59
-
60
- start = Time.now
61
- data.each do |d|
62
- (1..it).each do
63
- xml = d[2].to_s
64
- end
65
- end
66
- no_time = Time.now - start
67
- puts "to String #{it} times with nokogiri took #{no_time} seconds."
68
- =begin
69
- start = Time.now
70
- data.each do |d|
71
- xml = d[1]
72
- (1..it).each do
73
- xml = d[2].to_s
74
- end
75
- end
76
- no_time = Time.now - start
77
- puts "to file #{it} times with nokogiri took #{no_time} seconds.\n\n"
78
- =end
79
- puts "Ox is %0.1f faster than Nokogiri" % [no_time/ox_time]
80
- end
data/test/sample.rb DELETED
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env ruby -wW2
2
-
3
- if $0 == __FILE__
4
- $: << '.'
5
- $: << '..'
6
- $: << '../lib'
7
- $: << '../ext'
8
- end
9
-
10
- require 'pp'
11
- require 'sample/doc'
12
-
13
-
14
- def sample_doc(size=3)
15
- colors = [ :black, :gray, :white, :red, :blue, :yellow, :green, :purple, :orange ]
16
-
17
- d = ::Sample::Doc.new('Sample')
18
-
19
- # add some history
20
- (0..size * 10).each do |i|
21
- d.add_change("Changed at t+#{i}.")
22
- end
23
-
24
- # add some layers
25
- (1..size).each do |i|
26
- layer = ::Sample::Layer.new("Layer-#{i}")
27
- (1..size).each do |j|
28
- g = ::Sample::Group.new
29
- (1..size).each do |k|
30
- g2 = ::Sample::Group.new
31
- r = ::Sample::Rect.new(j * 40 + 10.0, i * 10.0,
32
- 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
33
- r.add_prop(:part_of, layer.name)
34
- g2 << r
35
- g2 << ::Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
36
- g << g2
37
- end
38
- g2 = ::Sample::Group.new
39
- (1..size).each do |k|
40
- o = ::Sample::Oval.new(j * 40 + 12.0, i * 10.0 + 2.0,
41
- 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
42
- o.add_prop(:inside, true)
43
- g << o
44
- end
45
- g << g2
46
- layer << g
47
- end
48
- d.layers[layer.name] = layer
49
- end
50
-
51
- # some properties
52
- d.add_prop(:purpose, 'an example')
53
-
54
- d
55
- end