Skip to content

Commit 097c5b3

Browse files
authored
Merge pull request #9 from ChevronETC/stk/bench
Use PkgBenchmark.jl for performance benchmarks
2 parents 1b12bf2 + a299713 commit 097c5b3

File tree

6 files changed

+118
-285
lines changed

6 files changed

+118
-285
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.nfs*
55
*.cov
66
docs/build
7+
teaseis-benchmarks-*
8+
results.md

benchmark/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Benchmarking
2+
We use [PkgBenchmark.jl](http://github.com/juliaCI/PkgBenchmark.jl) which can be
3+
installed using `Pkg.add("PkgBenchmark")`. To run the benchmarks:
4+
```julia
5+
using PkgBenchmark
6+
results=benchmarkpkg("TeaSeis")
7+
export_markdown("results.md", results)
8+
```
9+
In order to compare the benchmarks against a different version:
10+
```julia
11+
results=judge("TeaSeis", "e1d4076")
12+
export_markdown("results.md", results)
13+
```
14+
where `e1d4076` is a Git SHA. To run a specific benchmark:
15+
```julia
16+
benchmarks=include("benchmarks.jl")
17+
run(benchmarks["Frame operations"]["write,Float32"])
18+
```
19+
20+
You can profile a benchmark. For example:
21+
```julia
22+
benchmarks=include("benchmarks.jl")
23+
@profile run(benchmarks["Frame operations"]["write,Float32"])
24+
```
25+
Use `Profile.print()` and `using ProfileView; ProfileView.view()` to inspect the
26+
profile. Note that `ProfileView.view()` requires
27+
[ProfileView.jl](http://github.com/timholy/ProfileView.jl).
28+
29+
For more information, please see the documentation for
30+
[PkgBenchmark.jl](http://github.com/juliaCI/PkgBenchmark.jl) and
31+
[BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl).

benchmark/REQUIRE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
julia 0.5
2+
3+
BenchmarkTools

benchmark/benchmarks.jl

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using TeaSeis, BenchmarkTools
2+
3+
const fs="."
4+
const N1,N2,N3,N4,N5=100,11,12,2,3
5+
6+
makefname() = joinpath(fs, "teaseis-benchmarks-$(randstring())")
7+
rmjsfile(f) = rm(jsopen(f))
8+
9+
const SUITE = BenchmarkGroup()
10+
11+
makeframe(T) = begin f=makefname();io=jsopen(f,"w",axis_lengths=[N1,N2,1],dataformat=T); writeframe(io, rand(Float32,N1,N2), 1); io,f end
12+
makeframewrite(T) = begin io,f=makeframe(T); io,f,readframe(jsopen(f),1)... end
13+
makeframeread(T) = begin io,f=makeframe(T); jsopen(f),f end
14+
makeframeread!(T) = begin io,f=makeframe(T); jsopen(f),f,readframe(jsopen(f),1)... end
15+
16+
SUITE["Frame operations"] = BenchmarkGroup()
17+
for T in (Float32,Int16)
18+
SUITE["Frame operations"]["write,$T"] = @benchmarkable writeframe(io,d,h) setup=begin io,f,d,h=makeframewrite($T) end teardown=rmjsfile(f)
19+
SUITE["Frame operations"]["read,$T"] = @benchmarkable readframe(io,1) setup=begin io,f=makeframeread($T) end teardown=rmjsfile(f)
20+
SUITE["Frame operations"]["readtrcs,$T"] = @benchmarkable readframetrcs(io,1) setup=begin io,f=makeframeread($T) end teardown=rmjsfile(f)
21+
SUITE["Frame operations"]["readhdrs,$T"] = @benchmarkable readframehdrs(io,1) setup=begin io,f=makeframeread($T) end teardown=rmjsfile(f)
22+
SUITE["Frame operations"]["read!,$T"] = @benchmarkable readframe!(io,d,h,1) setup=begin io,f,d,h=makeframeread!($T) end teardown=rmjsfile(f)
23+
SUITE["Frame operations"]["readtrcs!,$T"] = @benchmarkable readframetrcs!(io,d,1) setup=begin io,f,d,h=makeframeread!($T) end teardown=rmjsfile(f)
24+
SUITE["Frame operations"]["readhdrs!,$T"] = @benchmarkable readframehdrs!(io,h,1) setup=begin io,f,d,h=makeframeread!($T) end teardown=rmjsfile(f)
25+
26+
SUITE["Frame operations"]["write,indexed,$T"] = @benchmarkable writeframe(io,d,1) setup=begin io,f,d,h=makeframewrite($T) end teardown=rmjsfile(f)
27+
28+
SUITE["Frame operations"]["allocframe,$T"] = @benchmarkable allocframe(io) setup=begin io,f=makeframe($T) end teardown=rmjsfile(f)
29+
SUITE["Frame operations"]["allocframetrcs,$T"] = @benchmarkable allocframetrcs(io) setup=begin io,f=makeframe($T) end teardown=rmjsfile(f)
30+
SUITE["Frame operations"]["allocframehdrs,$T"] = @benchmarkable allocframehdrs(io) setup=begin io,f=makeframe($T) end teardown=rmjsfile(f)
31+
32+
SUITE["Frame operations"]["binary write,$T"] = @benchmarkable begin io=open(f,"w");write(io,A);close(io) end setup=begin f=makefname();A=rand($T,$N1,$N2) end teardown=rm(f)
33+
SUITE["Frame operations"]["binary read,$T"] = @benchmarkable begin io=open(f);read(io,$T,$N1,$N2);close(io) end setup=begin f=makefname();write(f,rand($T,$N1,$N2)) end teardown=rm(f)
34+
SUITE["Frame operations"]["binary read!,$T"] = @benchmarkable begin io=open(f);read!(io,A);close(io) end setup=begin f=makefname();A=rand($T,$N1,$N2);write(f,A) end teardown=rm(f)
35+
end
36+
37+
makevolume(N,S) = begin f=makefname(); io=jsopen(f,"w",axis_lengths=[N...]); write(io, rand(Float32,N...), S...); io,f end
38+
makevolumewrite(N,S) = begin io,f=makevolume(N,S); io,f,read(jsopen(f),S...)... end
39+
makevolumeread(N,S) = begin io,f=makevolume(N,S); jsopen(f),f end
40+
makevolumeread!(N,S) = begin io,f=makevolume(N,S); jsopen(f),f,read(jsopen(f),S...)... end
41+
42+
SUITE["Slice IO"] = BenchmarkGroup()
43+
for (N,S) in (
44+
((N1,N2,N3), (Colon(),Colon(),Colon())),
45+
((N1,N2,N3,N4), (Colon(),Colon(),Colon(),Colon())),
46+
((N1,N2,N3,N4,N5), (Colon(),Colon(),Colon(),Colon(),Colon()))
47+
)
48+
D = string(" ",length(N),"D")
49+
50+
SUITE["Slice IO"][string("write",D)] = @benchmarkable write(io,d,h) setup=begin io,f,d,h=makevolumewrite($N,$S); end teardown=rmjsfile(f)
51+
SUITE["Slice IO"][string("writetrcs",D)] = @benchmarkable write(io,d,$(S)...) setup=begin io,f,d,h=makevolumewrite($N,$S) end teardown=rmjsfile(f)
52+
SUITE["Slice IO"][string("readtrcs",D)] = @benchmarkable readtrcs(io,$(S)...) setup=begin io,f=makevolumeread($N,$S) end teardown=rmjsfile(f)
53+
SUITE["Slice IO"][string("readtrcs!",D)] = @benchmarkable readtrcs!(io,d,$(S)...) setup=begin io,f,d,h=makevolumeread!($N,$S) end teardown=rmjsfile(f)
54+
SUITE["Slice IO"][string("readhdrs!",D)] = @benchmarkable readhdrs!(io,h,$(S)...) setup=begin io,f,d,h=makevolumeread!($N,$S) end teardown=rmjsfile(f)
55+
56+
SUITE["Slice IO"][string("binary write",D)] = @benchmarkable begin io=open(f,"w");write(io,d);close(io) end setup=begin f=makefname(); d=rand(Float32,$(N)...) end teardown=rm(f)
57+
SUITE["Slice IO"][string("binary read",D)] = @benchmarkable begin io=open(f);read(io,Float32,$(N)...);close(io) end setup=begin f=makefname(); write(f,rand(Float32,$(N)...)) end teardown=rm(f)
58+
SUITE["Slice IO"][string("binary read!",D)] = @benchmarkable begin io=open(f);read!(io,d);close(io) end setup=begin d=zeros(Float32,$(N)...); f=makefname(); write(f,d) end teardown=rm(f)
59+
end
60+
61+
function makepartialframe()
62+
f = makefname()
63+
io = jsopen(f,"w",axis_lengths=[N1,N2,1])
64+
d,h = allocframe(io)
65+
srand(0)
66+
rand!(d)
67+
alive = fill(false, N2)
68+
alive[randperm(N2)[1:div(N2,2)]] .= true
69+
for i = 1:N2
70+
set!(props(io,2), h, i, i)
71+
set!(props(io,3), h, i, 1)
72+
set!(prop(io,stockprop[:TRC_TYPE]), h, i, alive[i] ? tracetype[:live] : tracetype[:dead])
73+
end
74+
io,f,d,h
75+
end
76+
77+
SUITE["Partial frame"] = BenchmarkGroup()
78+
79+
SUITE["Partial frame"]["leftjustify!"] = @benchmarkable leftjustify!(io, d, h) setup=begin io,f,d,h=makepartialframe() end teardown=rmjsfile(f)
80+
SUITE["Partial frame"]["regularize!"] = @benchmarkable regularize!(io, d, h) setup=begin io,f,d,h=makepartialframe(); leftjustify!(io,d,h) end teardown=rmjsfile(f)
81+
SUITE["Partial frame"]["fold"] = @benchmarkable fold(io,h) setup=begin io,f,d,h=makepartialframe() end teardown=rmjsfile(f)
82+
SUITE["Partial frame"]["fold,1"] = @benchmarkable fold(io,1) setup=begin io,f,d,h=makepartialframe() end teardown=rmjsfile(f)

0 commit comments

Comments
 (0)