ox 1.0.0
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.
- data/LICENSE +27 -0
- data/README +153 -0
- data/ext/ox/base64.c +123 -0
- data/ext/ox/base64.h +44 -0
- data/ext/ox/cache.c +148 -0
- data/ext/ox/cache.h +43 -0
- data/ext/ox/cache8.c +80 -0
- data/ext/ox/cache8.h +43 -0
- data/ext/ox/cache8_test.c +69 -0
- data/ext/ox/cache_test.c +69 -0
- data/ext/ox/dump.c +901 -0
- data/ext/ox/extconf.rb +7 -0
- data/ext/ox/gen_load.c +196 -0
- data/ext/ox/obj_load.c +802 -0
- data/ext/ox/ox.c +456 -0
- data/ext/ox/ox.h +190 -0
- data/ext/ox/parse.c +629 -0
- data/lib/ox.rb +97 -0
- data/lib/ox/cdata.rb +12 -0
- data/lib/ox/comment.rb +13 -0
- data/lib/ox/doctype.rb +13 -0
- data/lib/ox/document.rb +20 -0
- data/lib/ox/element.rb +67 -0
- data/lib/ox/node.rb +24 -0
- data/test/Sample.graffle +2318 -0
- data/test/cache16_test.rb +17 -0
- data/test/cache8_test.rb +17 -0
- data/test/cache_test.rb +17 -0
- data/test/files.rb +34 -0
- data/test/func.rb +228 -0
- data/test/gen_sample.rb +22 -0
- data/test/obj_sample.rb +19 -0
- data/test/ox/change.rb +16 -0
- data/test/ox/dir.rb +21 -0
- data/test/ox/doc.rb +39 -0
- data/test/ox/file.rb +33 -0
- data/test/ox/group.rb +18 -0
- data/test/ox/hasprops.rb +18 -0
- data/test/ox/layer.rb +14 -0
- data/test/ox/line.rb +22 -0
- data/test/ox/oval.rb +12 -0
- data/test/ox/rect.rb +12 -0
- data/test/ox/shape.rb +37 -0
- data/test/ox/text.rb +23 -0
- data/test/perf_gen.rb +193 -0
- data/test/perf_mars.rb +97 -0
- data/test/perf_obj.rb +201 -0
- data/test/perf_pod.rb +88 -0
- data/test/perf_write.rb +80 -0
- data/test/sample.rb +62 -0
- data/test/test.rb +70 -0
- metadata +106 -0
data/test/ox/file.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require 'etc'
|
3
|
+
|
4
|
+
module Test
|
5
|
+
module Ox
|
6
|
+
|
7
|
+
class File
|
8
|
+
attr_accessor :name, :ctime, :mtime, :size, :owner, :group, :permissions
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
@name = ::File.basename(filename)
|
12
|
+
stat = ::File.stat(filename)
|
13
|
+
@ctime = stat.ctime
|
14
|
+
@mtime = stat.mtime
|
15
|
+
@size = stat.size
|
16
|
+
@owner = Etc.getpwuid(stat.uid).name
|
17
|
+
@group = Etc.getgrgid(stat.gid).name
|
18
|
+
@permissions = {
|
19
|
+
:user => [(0 != (stat.mode & 0x0100)) ? 'r' : '-',
|
20
|
+
(0 != (stat.mode & 0x0080)) ? 'w' : '-',
|
21
|
+
(0 != (stat.mode & 0x0040)) ? 'x' : '-'].join(''),
|
22
|
+
:group => [(0 != (stat.mode & 0x0020)) ? 'r' : '-',
|
23
|
+
(0 != (stat.mode & 0x0010)) ? 'w' : '-',
|
24
|
+
(0 != (stat.mode & 0x0008)) ? 'x' : '-'].join(''),
|
25
|
+
:other => [(0 != (stat.mode & 0x0004)) ? 'r' : '-',
|
26
|
+
(0 != (stat.mode & 0x0002)) ? 'w' : '-',
|
27
|
+
(0 != (stat.mode & 0x0001)) ? 'x' : '-'].join('')
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end # File
|
32
|
+
end # Ox
|
33
|
+
end # Test
|
data/test/ox/group.rb
ADDED
data/test/ox/hasprops.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module Test
|
3
|
+
module Ox
|
4
|
+
module HasProps
|
5
|
+
|
6
|
+
def add_prop(key, value)
|
7
|
+
@props = { } unless self.instance_variable_defined?(:@props)
|
8
|
+
@props[key] = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def props
|
12
|
+
@props = { } unless self.instance_variable_defined?(:@props)
|
13
|
+
@props
|
14
|
+
end
|
15
|
+
|
16
|
+
end # HashProps
|
17
|
+
end # Ox
|
18
|
+
end # Test
|
data/test/ox/layer.rb
ADDED
data/test/ox/line.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Test
|
2
|
+
module Ox
|
3
|
+
|
4
|
+
class Line
|
5
|
+
include HasProps
|
6
|
+
|
7
|
+
attr_accessor :x, :y, :dx, :dy
|
8
|
+
attr_accessor :color
|
9
|
+
attr_accessor :thick
|
10
|
+
|
11
|
+
def initialize(x, y, dx, dy, thick, color)
|
12
|
+
@x = x
|
13
|
+
@y = y
|
14
|
+
@dx = dx
|
15
|
+
@dy = dy
|
16
|
+
@thick = thick
|
17
|
+
@color = color
|
18
|
+
end
|
19
|
+
|
20
|
+
end # Line
|
21
|
+
end # Ox
|
22
|
+
end # Test
|
data/test/ox/oval.rb
ADDED
data/test/ox/rect.rb
ADDED
data/test/ox/shape.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module Test
|
3
|
+
module Ox
|
4
|
+
class Shape
|
5
|
+
include HasProps
|
6
|
+
|
7
|
+
attr_accessor :bounds
|
8
|
+
attr_accessor :color
|
9
|
+
attr_accessor :border, :border_color
|
10
|
+
|
11
|
+
def initialize(left, top, wide, high, color=nil)
|
12
|
+
@bounds = [[left, top], [left + wide, top + high]]
|
13
|
+
@color = color
|
14
|
+
@border = 1
|
15
|
+
@border_color = :black
|
16
|
+
end
|
17
|
+
|
18
|
+
def left
|
19
|
+
@bounds[0][0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def top
|
23
|
+
@bounds[0][1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def width
|
27
|
+
@bounds[1][0] - @bounds[0][0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def height
|
31
|
+
@bounds[1][1] - @bounds[0][1]
|
32
|
+
end
|
33
|
+
|
34
|
+
end # Shape
|
35
|
+
end # Ox
|
36
|
+
end # Test
|
37
|
+
|
data/test/ox/text.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module Test
|
3
|
+
module Ox
|
4
|
+
|
5
|
+
class Text < Shape
|
6
|
+
attr_accessor :text
|
7
|
+
attr_accessor :font
|
8
|
+
attr_accessor :font_size
|
9
|
+
attr_accessor :just
|
10
|
+
attr_accessor :text_color
|
11
|
+
|
12
|
+
def initialize(text, left, top, wide, high, color=nil)
|
13
|
+
super(left, top, wide, high, color)
|
14
|
+
@text = text
|
15
|
+
@font = 'helvetica'
|
16
|
+
@font_size = 14
|
17
|
+
@just = 'left'
|
18
|
+
@text_color = 'black'
|
19
|
+
end
|
20
|
+
|
21
|
+
end # Text
|
22
|
+
end # Ox
|
23
|
+
end # Test
|
data/test/perf_gen.rb
ADDED
@@ -0,0 +1,193 @@
|
|
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
|
+
require 'nokogiri'
|
21
|
+
|
22
|
+
$verbose = 0
|
23
|
+
$ox_only = false
|
24
|
+
|
25
|
+
do_sample = false
|
26
|
+
do_files = false
|
27
|
+
|
28
|
+
do_load = false
|
29
|
+
do_dump = false
|
30
|
+
do_read = false
|
31
|
+
do_write = false
|
32
|
+
$iter = 1000
|
33
|
+
|
34
|
+
opts = OptionParser.new
|
35
|
+
opts.on("-v", "increase verbosity") { $verbose += 1 }
|
36
|
+
|
37
|
+
opts.on("-x", "ox only") { $ox_only = true }
|
38
|
+
|
39
|
+
opts.on("-s", "load and dump as sample Ruby object") { do_sample = true }
|
40
|
+
opts.on("-f", "load and dump as files Ruby object") { do_files = true }
|
41
|
+
|
42
|
+
opts.on("-l", "load") { do_load = true }
|
43
|
+
opts.on("-d", "dump") { do_dump = true }
|
44
|
+
opts.on("-r", "read") { do_read = true }
|
45
|
+
opts.on("-w", "write") { do_write = true }
|
46
|
+
opts.on("-a", "load, dump, read and write") { do_load = true; do_dump = true; do_read = true; do_write = true }
|
47
|
+
|
48
|
+
opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| $iter = i }
|
49
|
+
|
50
|
+
opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
|
51
|
+
files = opts.parse(ARGV)
|
52
|
+
|
53
|
+
if files.empty?
|
54
|
+
data = []
|
55
|
+
obj = do_sample ? sample_doc(2) : files('..')
|
56
|
+
xml = Ox.dump(obj, :indent => 2, :opt_format => true)
|
57
|
+
gen = Ox.parse(xml)
|
58
|
+
no = Nokogiri::XML::Document.parse(xml)
|
59
|
+
File.open('sample.xml', 'w') { |f| f.write(xml) }
|
60
|
+
data << { :file => 'sample.xml', :xml => xml, :ox => gen, :nokogiri => no }
|
61
|
+
else
|
62
|
+
puts "loading and parsing #{files}\n\n"
|
63
|
+
data = files.map do |f|
|
64
|
+
xml = File.read(f)
|
65
|
+
obj = Ox.parse(xml);
|
66
|
+
gen = Ox.parse(xml)
|
67
|
+
no = Nokogiri::XML::Document.parse(xml)
|
68
|
+
{ :file => f, :xml => xml, :ox => gen, :nokogiri => no }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
$ox_load_time = 0
|
73
|
+
$no_load_time = 0
|
74
|
+
$ox_dump_time = 0
|
75
|
+
$no_dump_time = 0
|
76
|
+
|
77
|
+
def perf_load(d)
|
78
|
+
xml = d[:xml]
|
79
|
+
|
80
|
+
if 0 < $verbose
|
81
|
+
obj = Ox.load(xml, :mode => :generic, :trace => $verbose)
|
82
|
+
return
|
83
|
+
end
|
84
|
+
start = Time.now
|
85
|
+
(1..$iter).each do
|
86
|
+
#obj = Ox.load(xml, :mode => :generic)
|
87
|
+
obj = Ox.parse(xml)
|
88
|
+
end
|
89
|
+
$ox_load_time = Time.now - start
|
90
|
+
puts "Parsing #{$iter} times with Ox took #{$ox_load_time} seconds."
|
91
|
+
|
92
|
+
return if $ox_only
|
93
|
+
|
94
|
+
start = Time.now
|
95
|
+
(1..$iter).each do
|
96
|
+
obj = Nokogiri::XML::Document.parse(xml)
|
97
|
+
#obj = Nokogiri::XML::Document.parse(xml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS)
|
98
|
+
end
|
99
|
+
$no_load_time = Time.now - start
|
100
|
+
puts "Nokogiri parse #{$iter} times took #{$no_load_time} seconds."
|
101
|
+
puts ">>> Ox is %0.1f faster than Nokogiri parsing.\n\n" % [$no_load_time/$ox_load_time]
|
102
|
+
end
|
103
|
+
|
104
|
+
def perf_dump(d)
|
105
|
+
obj = d[:ox]
|
106
|
+
|
107
|
+
start = Time.now
|
108
|
+
(1..$iter).each do
|
109
|
+
xml = Ox.dump(obj, :indent => 2)
|
110
|
+
# puts "*** ox:\n#{xml}"
|
111
|
+
end
|
112
|
+
$ox_dump_time = Time.now - start
|
113
|
+
puts "Ox dumping #{$iter} times with ox took #{$ox_dump_time} seconds."
|
114
|
+
|
115
|
+
return if $ox_only
|
116
|
+
|
117
|
+
obj = d[:nokogiri]
|
118
|
+
start = Time.now
|
119
|
+
(1..$iter).each do
|
120
|
+
xml = obj.to_xml(:indent => 0)
|
121
|
+
end
|
122
|
+
$no_dump_time = Time.now - start
|
123
|
+
puts "Nokogiri to_xml #{$iter} times took #{$no_dump_time} seconds."
|
124
|
+
puts ">>> Ox is %0.1f faster than Nokkgiri to_xml.\n\n" % [$no_dump_time/$ox_dump_time]
|
125
|
+
end
|
126
|
+
|
127
|
+
def perf_read(d)
|
128
|
+
ox_read_time = 0
|
129
|
+
|
130
|
+
filename = d[:file]
|
131
|
+
|
132
|
+
# now load from the file
|
133
|
+
start = Time.now
|
134
|
+
(1..$iter).each do
|
135
|
+
obj = Ox.load_file(filename, :mode => :generic)
|
136
|
+
end
|
137
|
+
ox_read_time = Time.now - start
|
138
|
+
puts "Loading and parsing #{$iter} times with ox took #{ox_read_time} seconds."
|
139
|
+
|
140
|
+
if !$ox_only
|
141
|
+
start = Time.now
|
142
|
+
(1..$iter).each do
|
143
|
+
xml = File.read(filename)
|
144
|
+
obj = Nokogiri::XML::Document.parse(xml)
|
145
|
+
end
|
146
|
+
no_read_time = Time.now - start
|
147
|
+
puts "Reading and parsing #{$iter} times took #{no_read_time} seconds."
|
148
|
+
puts ">>> Ox is %0.1f faster than Nokogiri loading and parsing.\n\n" % [no_read_time/ox_read_time]
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def perf_write(d)
|
154
|
+
ox_write_time = 0
|
155
|
+
|
156
|
+
filename = 'out.xml'
|
157
|
+
no = 'out.xml'
|
158
|
+
obj = d[:ox]
|
159
|
+
|
160
|
+
start = Time.now
|
161
|
+
(1..$iter).each do
|
162
|
+
xml = Ox.to_file(filename, obj, :indent => 0)
|
163
|
+
end
|
164
|
+
ox_write_time = Time.now - start
|
165
|
+
puts "Ox dumping #{$iter} times with ox took #{ox_write_time} seconds."
|
166
|
+
|
167
|
+
if !$ox_only
|
168
|
+
obj = d[:nokogiri]
|
169
|
+
start = Time.now
|
170
|
+
(1..$iter).each do
|
171
|
+
xml = obj.to_xml(:indent => 0)
|
172
|
+
File.open(filename, "w") { |f| f.write(xml) }
|
173
|
+
end
|
174
|
+
no_write_time = Time.now - start
|
175
|
+
puts "Nokogiri dumping and writing #{$iter} times took #{no_write_time} seconds."
|
176
|
+
puts ">>> Ox is %0.1f faster than Nokogiri writing.\n\n" % [no_write_time/ox_write_time]
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
data.each do |d|
|
182
|
+
puts "Using file #{d[:file]}."
|
183
|
+
|
184
|
+
perf_load(d) if do_load
|
185
|
+
perf_dump(d) if do_dump
|
186
|
+
if do_load and do_dump
|
187
|
+
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
|
188
|
+
end
|
189
|
+
|
190
|
+
perf_read(d) if do_read
|
191
|
+
perf_write(d) if do_write
|
192
|
+
|
193
|
+
end
|
data/test/perf_mars.rb
ADDED
@@ -0,0 +1,97 @@
|
|
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 "type Ox Marshal ratio"
|
78
|
+
data.each do |type,a|
|
79
|
+
#xml = Ox.dump(a, :indent => -1, :xsd_date => true)
|
80
|
+
xml = Ox.dump(a, :indent => -1)
|
81
|
+
#pp a
|
82
|
+
#puts xml
|
83
|
+
start = Time.now
|
84
|
+
(1..it).each do
|
85
|
+
obj = Ox.load(xml, :mode => :object)
|
86
|
+
#pp obj
|
87
|
+
end
|
88
|
+
ox_time = Time.now - start
|
89
|
+
|
90
|
+
m = Marshal.dump(a)
|
91
|
+
start = Time.now
|
92
|
+
(1..it).each do
|
93
|
+
obj = Marshal.load(m)
|
94
|
+
end
|
95
|
+
marshal_time = Time.now - start
|
96
|
+
puts "%8s %6.3f %6.3f %0.1f" % [type.to_s, ox_time, marshal_time, marshal_time / ox_time]
|
97
|
+
end
|