Skip to content

Commit 810d98e

Browse files
committed
add write benchmark
1 parent 4b6f292 commit 810d98e

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ Platform Info:
155155
XMLDict.xml_dict ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1350.63
156156
```
157157

158+
### Writing an XML File
159+
160+
```
161+
Write: XML ■■■■■■■■■■■■■■■■■■■■■■ 244.261
162+
Write: EzXML ■■■■■■■■■■ 106.953
163+
```
164+
158165
### Lazily Iterating over Each Node
159166
```
160167
LazyNode ■■■■■■■■■■■■■■■■ 55.1

benchmarks/suite.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ file = joinpath(@__DIR__, "nasa.xml")
2020

2121
df = DataFrame(kind=String[], name=String[], bench=BenchmarkTools.Trial[])
2222

23+
24+
#-----------------------------------------------------------------------------# Write
25+
kind = "Write"
26+
output = tempname()
27+
28+
name = "XML.write 2"
29+
@info name
30+
node1 = read(file, Node)
31+
bench = @benchmark XML.write($output, $node1)
32+
push!(df, (;kind, name, bench))
33+
34+
35+
name = "EzXML.writexml"
36+
@info name
37+
node2 = EzXML.readxml(file)
38+
bench = @benchmark EzXML.write($output, $node2)
39+
push!(df, (;kind, name, bench))
40+
41+
42+
2343
#-----------------------------------------------------------------------------# Read
2444
kind = "Read"
2545

@@ -99,6 +119,8 @@ push!(df, (;kind, name, bench))
99119

100120

101121

122+
123+
102124
#-----------------------------------------------------------------------------# Plots
103125
function plot(df, kind)
104126
g = groupby(df, :kind)
@@ -109,5 +131,6 @@ function plot(df, kind)
109131
end
110132

111133
plot(df, "Read")
134+
plot(df, "Write")
112135
plot(df, "Lazy Iteration")
113136
plot(df, "Collect Tags")

src/XML.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function _show_node(io::IO, o)
229229
printstyled(io, ' ', repr(value(o)))
230230
elseif o.nodetype === Element
231231
printstyled(io, " <", tag(o), color=:light_cyan)
232-
_print_attrs(io, o)
232+
_print_attrs(io, o; color=:light_yellow)
233233
printstyled(io, '>', color=:light_cyan)
234234
_print_n_children(io, o)
235235
elseif o.nodetype === DTD
@@ -238,11 +238,11 @@ function _show_node(io::IO, o)
238238
printstyled(io, '>', color=:light_cyan)
239239
elseif o.nodetype === Declaration
240240
printstyled(io, " <?xml", color=:light_cyan)
241-
_print_attrs(io, o)
241+
_print_attrs(io, o; color=:light_yellow)
242242
printstyled(io, "?>", color=:light_cyan)
243243
elseif o.nodetype === ProcessingInstruction
244244
printstyled(io, " <?", tag(o), color=:light_cyan)
245-
_print_attrs(io, o)
245+
_print_attrs(io, o; color=:light_yellow)
246246
printstyled(io, "?>", color=:light_cyan)
247247
elseif o.nodetype === Comment
248248
printstyled(io, " <!--", color=:light_cyan)
@@ -262,9 +262,12 @@ function _show_node(io::IO, o)
262262
end
263263
end
264264

265-
function _print_attrs(io::IO, o)
266-
x = attributes(o)
267-
!isnothing(x) && printstyled(io, [" $k=\"$v\"" for (k,v) in x]...; color=:light_yellow)
265+
function _print_attrs(io::IO, o; color=:normal)
266+
attr = attributes(o)
267+
isnothing(attr) && return nothing
268+
for (k,v) in attr
269+
printstyled(io, ' ', k, '=', '"', v, '"'; color)
270+
end
268271
end
269272
function _print_n_children(io::IO, o::Node)
270273
n = length(children(o))

0 commit comments

Comments
 (0)