説明した関数が与えられていると、各引数を個別にプロファイリングしてから、引数を独立させることができます。
# wrap function in timer
myfun_time <- function(i,j, type = "user.self"){
system.time(myfun(i,j))[type]
}
# choose points to evaluate at
i_vals <- c(0,10,50,100,120)
j_vals <- c(0,10,50,100,150)
# create evaluation matrix (all combinations of points)
eval_mat <- expand.grid(i = i_vals, j = j_vals)
# create matrix to help with location of points when moving from vector to matrix
loc_mat <- as.matrix(expand.grid(i = 1:length(i_vals), j = 1:length(j_vals)))
# run test
results_vec <- mapply(myfun_time, i = eval_mat$i, j = eval_mat$j)
# empty matrix to store results
results_mat <- matrix(NA, nrow = sqrt(nrow(eval_mat)), ncol = sqrt(nrow(eval_mat)),
dimnames = list(i_vals,j_vals))
# move results vector to matrix
results_mat[loc_mat] <- results_vec
# you can also repeat this and average the results...