# Get the full example network that is stored in the package
network <- kwb.graph::exampleNetwork(n_links = -1L)
# For the comparison of run times, initialise vectors holding run times
runtime.R <- vector()
runtime.C1 <- vector()
runtime.C2 <- vector()
# Function to run code in "exp" and return elapsed time
elapsed <- function(exp) system.time(exp)["elapsed"]
# Shortcut to the main function. Arguments "resultSize" and "queueSize" are
# required by the C-versions of getConnectedLinks(), TODO: find proper values
# within getConnectedLinks()!
run <- function(version) kwb.graph::getConnectedLinks(
network,
version = version,
resultSize = 2054851,
queueSize = 100*1024
)
# Number of repetitions for run time comparison
n <- 3L
# Compare run times of three different implementations of the "collect links
# upstream" algorithm within getConnectedLinks()
for (i in seq_len(n)) {
cat("run", i, "/", n, "\n")
runtime.R[i] <- elapsed(x1 <- run(version = 1L))
runtime.C1[i] <- elapsed(x2 <- run(version = 2L))
runtime.C2[i] <- elapsed(x3 <- run(version = 3L))
}
#> run 1 / 3
#> run 2 / 3
#> run 3 / 3
(runtimeData <- data.frame(
version = 1:3,
implementation = c("R-functions", "C-functions(1)", "C-functions(2)"),
mean_runtime = sapply(list(runtime.R, runtime.C1, runtime.C2), mean)
))
#> version implementation mean_runtime
#> 1 1 R-functions 1.1076667
#> 2 2 C-functions(1) 0.3926667
#> 3 3 C-functions(2) 0.3920000
boxplot(mean_runtime ~ version, data = runtimeData)