Skip to content

Instantly share code, notes, and snippets.

@maxdrohde
Created March 13, 2025 00:37
Show Gist options
  • Save maxdrohde/2582d3e8b007f246305148fc21a5dac2 to your computer and use it in GitHub Desktop.
Save maxdrohde/2582d3e8b007f246305148fc21a5dac2 to your computer and use it in GitHub Desktop.
See how parallel computing is working in practice vs optimal speedup
library(furrr)
x <- numeric()
for (i in 1:20) {
future::plan(multisession, workers = i)
result <- system.time({
r <- furrr::future_map(1:100,
~ sum(rnorm(1e7)),
.options = furrr_options(seed=TRUE))
})
print(result[[3]])
x <- c(x, result[[3]])
}
# PLOT
plot(1:20, x, type = "b", col = "blue", pch = 16, lty = 1, ylim = range(c(x, x / (1:20))),
xlab = "Index", ylab = "Values", main = "Actual vs Optimal")
lines(1:20, x / (1:20), type = "b", col = "red", pch = 17, lty = 2)
legend("topright", legend = c("x", "x / (1:20)"), col = c("blue", "red"),
pch = c(16, 17), lty = c(1, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment