|
| 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