mihaiconstantin / powerly

`powerly` is an R package for conducting sample size analysis for network models and more.
https://powerly.dev
Other
7 stars 3 forks source link

The duration filed on the `Method` class is incorrectly reported in `summary` #9

Closed mihaiconstantin closed 2 years ago

mihaiconstantin commented 2 years ago

The duration field of the Method class is determined based on

https://github.com/mihaiconstantin/powerly/blob/d6be4e671a391c2614a919135e4e0292fe2cd381/R/Method.R#L172-L179

as

https://github.com/mihaiconstantin/powerly/blob/d6be4e671a391c2614a919135e4e0292fe2cd381/R/Method.R#L184-L185

and then reported in the summary as follows:

https://github.com/mihaiconstantin/powerly/blob/d6be4e671a391c2614a919135e4e0292fe2cd381/R/Method.R#L210-L211

When the method takes more the 60 seconds, the units of the duration field change from seconds to minutes, courtesy of the default difftime function. For example:

start <- Sys.time() - 61
end <- Sys.time()

print(start)
# "2022-04-29 15:22:52 CEST"

print(end)
# "2022-04-29 15:23:53 CEST"

duration <- end - start
cat("Method run completed (", as.numeric(round(duration, 4)), " sec)", sep = "")
# Method run completed (1.0194 sec)

I think it's better to just use the same unit everywhere, e.g.:

duration <- difftime(end, start, units = "secs")
cat("Method run completed (", as.numeric(round(duration, 4)), " sec)", sep = "")
# Method run completed (61.1642 sec)

This applies to other classes that have duration fields as well.