Hi @nperez
This is a small modification of Reorder(). When I examined Clim() efficiency yesterday, I noticed that Reorder() had room to be improved. Though Reorder() is not the major cause of Clim() slow speed and large memory consumption, it is used in many s2dv functions. So I think it's good to improve it even if the difference is not significant. I leave the testing code and results below.
Cheers,
An-Chi
library(rbenchmark)
data <- array(rnorm(1:60000),
dim = c(dat = 1, time = 12, member = 60, lon = 20, lat = 50))
attributes(data)$time <- 1:12
attributes(data)$dataset <- 'erainterim'
attributes(data)$units <- 'mm'
attributes(data)$prec <- list(units = 'mm', region = 'Europe')
order <- c('lat', 'lon', 'member', 'dat', 'time')
# Mean along 1 dim
benchmark("s2dv, old" = {
res <- s2dv::Reorder(data, order)
},
"s2dv, new" = {
res <- Reorder(data, order)
},
replications = 10,
columns = c("test", "replications", "elapsed",
"relative", "user.self", "sys.self"))
# without attributes
test replications elapsed relative user.self sys.self
2 s2dv, new 10 0.077 1.000 0.061 0.016
1 s2dv, old 10 0.101 1.312 0.093 0.008
# with attributes
test replications elapsed relative user.self sys.self
2 s2dv, new 10 0.107 1.000 0.108 0
1 s2dv, old 10 0.112 1.047 0.112 0