Skip to content

Commit 9be9c75

Browse files
committed
benchmark cleanup
1 parent f7e5fa9 commit 9be9c75

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,20 @@ XML.write(node) # String
122122
## Performance
123123

124124
- Comparing benchmarks (fairly) between packages is hard.
125-
- The most fair comparison is between `XML.jl - Node Load` and `XMLDict.jl - read` in which XMLDict is 1.4x slower.
125+
- The most fair comparison is between `XML.Node` and `XMLDict.xml_dict`.
126126
- See the `benchmarks/suite.jl` file.
127127

128-
| Benchmark | code | median time | median GC |
129-
|-----------|------|-------------|-----------|
130-
| XML.jl - Raw Data load | `XML.Raw($file)` | 10.083 μs | 0.00% |
131-
| XMLjl - LazyNode load | `LazyNode($file)` | 10.250 μs | 0.00% |
132-
| XML.jl - collect LazyNode | `collect(LazyNode($file))` | 102.149 ms | 24.51% GC |
133-
| XML.jl - Node load | `Node($file)` | 1.085 s | 16.16% |
134-
| EzXML.jl - read | `EzXML.readxml($file) | 192.345 ms | N/A |
135-
| XMLDict.jl - read | `XMLDict.xml_dict(read($file, String))` | 1.525 s | GC 23.17%
136-
| XML.jl LazyNode iteration | `for x in XML.LazyNode($file); end` | 67.547 ms | 16.55% GC
137-
| EzXML.StreamReader | `r = open(EzXML.StreamReader, $file); for x in r; end; close(r))` | 142.340 ms | N/A
128+
```
129+
8×2 DataFrame
130+
Row │ name bench
131+
│ String Trial
132+
─────┼───────────────────────────────────────────
133+
1 │ XML.Raw Trial(9.958 μs)
134+
2 │ XML.LazyNode Trial(10.000 μs)
135+
3 │ collect(XML.LazyNode) Trial(56.973 ms)
136+
4 │ XML.Node Trial(990.248 ms)
137+
5 │ EzXML.readxml Trial(158.977 ms)
138+
6 │ XMLDict.xml_dict Trial(1.278 s)
139+
7 │ XML.LazyNode iteration Trial(58.164 ms)
140+
8 │ EzXML.StreamReader Trial(138.631 ms)
141+
```

benchmarks/suite.jl

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,47 @@ using XML: XML
22
using EzXML: EzXML
33
using XMLDict: XMLDict
44
using BenchmarkTools
5+
using DataFrames
56

67

78
# nasa.xml was downloaded from:
89
# http://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/www/repository.html#nasa
910
file = joinpath(@__DIR__, "nasa.xml")
1011

11-
#-----------------------------------------------------------------------------# Read
12-
@info "XML.Raw" @benchmark XML.Raw($file) # median: 10.083 μs (0.00% GC)
13-
@info "XML.LazyNode" @benchmark XML.LazyNode($file) # median: 10.250 μs (0.00% GC)
14-
@info "collect(XML.LazyNode)" @benchmark collect(XML.LazyNode($file)) # median 102.149 ms (24.51% GC)
15-
@info "XML.Node" @benchmark Node($file) # median: 1.085 s (16.16% GC)
16-
@info "EzXML.readxml" @benchmark EzXML.readxml($file) # median: 192.345 ms
17-
@info "XMLDict.xml_dict" @benchmark XMLDict.xml_dict(read($file, String)) # median: 1.525 s (GC 23.17%)
18-
19-
#-----------------------------------------------------------------------------# Iteration
20-
@info "XML.LazyNode iteration" @benchmark (for x in XML.LazyNode($file); end) # 67.547 ms (16.55% GC)
21-
@info "EzXML.StreamReader" @benchmark (reader = open(EzXML.StreamReader, $file); for x in reader; end; close(reader)) # median 142.340 ms
12+
13+
14+
#-----------------------------------------------------------------------------# benchmarks
15+
benchmarks = []
16+
17+
@info "XML.Raw"
18+
push!(benchmarks, "XML.Raw" => @benchmark(read($file, XML.Raw)))
19+
20+
@info "XML.LazyNode"
21+
push!(benchmarks, "XML.LazyNode" => @benchmark(read($file, LazyNode)))
22+
23+
@info "collect(LazyNode)"
24+
push!(benchmarks, "collect(XML.LazyNode)" => @benchmark(collect(read($file, LazyNode))))
25+
26+
@info "XML.Node"
27+
push!(benchmarks, "XML.Node" => @benchmark(read($file, Node)))
28+
29+
@info "EzXML"
30+
push!(benchmarks, "EzXML.readxml" => @benchmark(EzXML.readxml($file)))
31+
32+
@info "XMLDict"
33+
push!(benchmarks, "XMLDict.xml_dict" => @benchmark(XMLDict.xml_dict(read($file, String))))
34+
35+
@info "LazyNode iteration"
36+
push!(benchmarks, "XML.LazyNode iteration" => @benchmark((for x in read($file, LazyNode); end)))
37+
38+
@info "EzXML.StreamReader iteration"
39+
push!(benchmarks, "EzXML.StreamReader" => @benchmark((reader = open(EzXML.StreamReader, $file); for x in reader; end; close(reader))))
40+
41+
#-----------------------------------------------------------------------------# make DataFrame
42+
out = DataFrame()
43+
44+
for (name, bench) in benchmarks
45+
push!(out, (; name, bench))
46+
end
47+
48+
out

0 commit comments

Comments
 (0)