library(s2dv)

data <- array(rnorm(1:60000),
              dim = c(dat = 1, sdate = 30, ftime = 4, member = 6, lon = 20, lat = 50))
time1 <- Sys.time()
res <- Season(data, monini = 11, moninf = 12, monsup = 1)
time2 <- Sys.time()
time.taken <- time2 - time1
print(time.taken)

time1 <- Sys.time()
res <- Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 2)
time2 <- Sys.time()
time.taken <- time2 - time1
print(time.taken)

time1 <- Sys.time()
res <- Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 4)
time2 <- Sys.time()
time.taken <- time2 - time1
print(time.taken)


library(rbenchmark)

# Mean along 1 dim
benchmark(
          "s2dv, 1 core" = {
            data <- array(rnorm(1:60000),
                          dim = c(dat = 1, ftime = 120, member = 6, lon = 20, lat = 50))
            res <- s2dv::Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 2)
          },
          "s2dv, 4 cores" = {
            data <- array(rnorm(1:60000),
                          dim = c(dat = 1, ftime = 120, member = 6, lon = 20, lat = 50))
            res <- s2dv::Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 4)
          },

          "s2dverification" = {
             data <- array(rnorm(1:60000),
                           dim = c(dat = 1, ftime = 120, member = 6, lon = 20, lat = 50))
             res <- s2dverification::Season(data, monini = 11, moninf = 12, monsup = 1)
          },
          replications = 10,
          columns = c("test", "replications", "elapsed",
                      "relative", "user.self", "sys.self"))

benchmark(
          "s2dv, 1 core" = {
            data <- array(rnorm(1:60000),
              dim = c(dat = 1, sdate = 30, ftime = 4, member = 6, lon = 20, lat = 50))
            res <- s2dv::Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 2)
          },
          "s2dv, 4 cores" = {
            data <- array(rnorm(1:60000),
              dim = c(dat = 1, sdate = 30, ftime = 4, member = 6, lon = 20, lat = 50))
            res <- s2dv::Season(data, monini = 11, moninf = 12, monsup = 1, ncores = 4)
          },

          "s2dverification" = {
             data <- array(rnorm(1:60000),
               dim = c(dat = 1, sdate = 30, ftime = 4, member = 6, lon = 20, lat = 50))
             res <- s2dverification::Season(data, monini = 11, moninf = 12, monsup = 1)
          },
          replications = 10,
          columns = c("test", "replications", "elapsed",
                      "relative", "user.self", "sys.self"))
# member = 6, ftime = 12
             test replications elapsed relative user.self sys.self
1    s2dv, 1 core           10   6.933  103.478     0.100    0.112
2   s2dv, 2 cores           10   6.885  102.761     0.120    0.088
3 s2dverification           10   0.067    1.000     0.064    0.004

# member = 50, ftime = 12
             test replications elapsed relative user.self sys.self
1    s2dv, 1 core           10  54.112  378.406     0.192    0.188
2   s2dv, 2 cores           10  54.183  378.902     0.204    0.176
3 s2dverification           10   0.143    1.000     0.140    0.004

# member = 6, ftime = 120
             test replications elapsed relative user.self sys.self
1    s2dv, 1 core           10  11.476   68.719     0.236    0.204
2   s2dv, 2 cores           10  11.664   69.844     0.272    0.172
3 s2dverification           10   0.167    1.000     0.156    0.012
> 

