Skip to content

Commit

Permalink
update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Jan 15, 2024
1 parent c28970b commit 07506ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions test/perf/benchmark-R-ncdf4.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ print(paste("ncdf4 version: ",packageVersion("ncdf4")))
fname = "filename_fv.nc"

process <- function(fname) {
# drop file caches; requires root
fileConn<-file("/proc/sys/vm/drop_caches",open = "wt")
writeLines("3", fileConn)
close(fileConn)

nc = nc_open(fname)

# how do you get the dimension from the file?
Expand Down
5 changes: 4 additions & 1 deletion test/perf/benchmark-julia-NCDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function compute(v)
end

function process(fname)
# drop file caches; requires root
write("/proc/sys/vm/drop_caches","3")

ds = NCDataset(fname,"r") do ds
v = ds["v1"];
tot = compute(v)
Expand All @@ -24,7 +27,7 @@ end
fname = "filename_fv.nc"
tot = process(fname)

@show tot
println("result ",tot)

bm = run(@benchmarkable process(fname) samples=100 seconds=10000)

Expand Down
21 changes: 13 additions & 8 deletions test/perf/benchmark-python-netCDF4.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ def compute(v):
return tot/v.shape[0]

def process(fname):
with open("/proc/sys/vm/drop_caches","w") as f:
f.write("3")

with netCDF4.Dataset(fname) as ds:
v = ds["v1"]
tot = compute(v)
return tot

def process_example():

if __name__ == "__main__":
fname = "filename_fv.nc";
process(fname)
tot = process(fname)

print("result ",tot)

setup = "from __main__ import process_example"
print("python-netCDF4 version ",netCDF4.__version__)
setup = "from __main__ import process"
print("python-netCDF4 version ",netCDF4.__version__)

benchtime = timeit.repeat("process_example()", setup=setup,number = 1, repeat = 100)
with open("python-netCDF4.txt","w") as f:
for bt in benchtime:
print(bt,file=f)
benchtime = timeit.repeat(lambda: process(fname), setup=setup,number = 1, repeat = 100)
with open("python-netCDF4.txt","w") as f:
for bt in benchtime:
print(bt,file=f)

0 comments on commit 07506ac

Please sign in to comment.