Apply() not as fast as apply() when simple functions are applied to a single array
As reported by @ncortesi , in a system with 10 cores, Apply() using all of these cores is only as fast as apply() using a single core when a simple, fast function is applied.
The case reported is the following:
library(multiApply)
my.array <- array(rnorm(10000000), c(1000,1000,100))
f <- function(x) max(x + 5 * x * x)
system.time({apply(my.array, c(1, 2), f)})
#~8 seconds
system.time({Apply(my.array, 3, f)})
#~40 seconds
system.time({Apply(my.array, 3, f, ncores = 10)})
#~9 seconds
The apply() code has been tested in a similar system with only 1 core and the wall-clock time has been also approx. 8 seconds (i.e. apply() is not using implicit multi-core).
This could be improved possibly by making use of apply() inside Apply() in the cases where only one input array is provided.
In cases where the function to be applied takes longer, Apply() can still be useful and improve the wall-clock time by using multi-core.
In conclusion, apply() should be recommended over Apply() for cases where functions are to be applied over large margins of a single data array. If the function to be applied is complex/slow, using Apply() with multiple cores can lead to a reduced wall-clock time (at the expense of greater computing resource usage) compared to the apply() implementation.