diff --git a/README.md b/README.md index 7f03f90b..06b692f0 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,8 @@ summary(sir) #> Number of entities : 0 #> Days (duration) : 50 (of 50) #> Number of viruses : 1 -#> Last run elapsed t : 172.00ms -#> Last run speed : 29.03 million agents x day / second +#> Last run elapsed t : 170.00ms +#> Last run speed : 29.29 million agents x day / second #> Rewiring : off #> #> Global actions: diff --git a/playground/benchmark-seir.R b/playground/benchmark-seir.R new file mode 100644 index 00000000..807de96d --- /dev/null +++ b/playground/benchmark-seir.R @@ -0,0 +1,50 @@ +library(epiworldR) +library(epiworldRfaster) + +library(microbenchmark) + +ns <- c(1e3, 5e3, 1e4, 5e4, 1e5, 5e5) +ans <- vector("list", length(ns)) +names(ans) <- as.character(ns) +for (n in ns) { + + sir <- epiworldR::ModelSEIR( + name = "COVID-19", + prevalence = 0.01, + incubation_days = 7, + transmission_rate = 0.6, + recovery_rate = 0.5 + ) |> + epiworldR::agents_smallworld(n = n, k = 20, p = 0.0, d = FALSE) |> + epiworldR::add_virus( + epiworldR::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .2 + ) |> + epiworldR::verbose_off() + + + sirfast <- epiworldRfaster::ModelSEIR( + name = "COVID-19", + prevalence = 0.01, + incubation_days = 7, + transmission_rate = 0.6, + recovery_rate = 0.5 + ) |> + epiworldRfaster::agents_smallworld(n = n, k = 20, p = 0, d = FALSE) |> + epiworldRfaster::add_virus( + epiworldRfaster::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .2 + ) |> + epiworldRfaster::verbose_off() + + + ans[[as.character(n)]] <- microbenchmark( + old = epiworldR::run(sir, ndays = 100, seed = 1912), + new = epiworldRfaster::run(sirfast, ndays = 100, seed = 1912), + times = 10 + ) + + message("Simulation with ", n, " individuals finished.") + +} + +saveRDS(ans, "playground/benchmark-seir.rds") + diff --git a/playground/benchmark-seirconn.R b/playground/benchmark-seirconn.R new file mode 100644 index 00000000..6e6a947b --- /dev/null +++ b/playground/benchmark-seirconn.R @@ -0,0 +1,52 @@ +library(epiworldR) +library(epiworldRfaster) + +library(microbenchmark) + +ns <- c(1e3, 5e3, 1e4, 5e4, 1e5, 5e5) +ans <- vector("list", length(ns)) +names(ans) <- as.character(ns) +for (n in ns) { + + sir <- epiworldR::ModelSEIRCONN( + name = "COVID-19", + prevalence = 0.01, + n = n, + contact_rate = 4, + incubation_days = 7, + transmission_rate = 0.6, + recovery_rate = 0.5 + ) |> + epiworldR::add_virus( + epiworldR::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .2 + ) |> + epiworldR::verbose_off() + + + sirfast <- epiworldRfaster::ModelSEIRCONN( + name = "COVID-19", + prevalence = 0.01, + n = n, + contact_rate = 4, + incubation_days = 7, + transmission_rate = 0.6, + recovery_rate = 0.5 + ) |> + epiworldRfaster::add_virus( + epiworldRfaster::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .2 + ) |> + epiworldRfaster::verbose_off() + + + ans[[as.character(n)]] <- microbenchmark( + old = epiworldR::run(sir, ndays = 100, seed = 1912), + new = epiworldRfaster::run(sirfast, ndays = 100, seed = 1912), + times = 10 + ) + + message("Simulation with ", n, " individuals finished.") + +} + +saveRDS(ans, "playground/benchmark-seirconn.rds") + diff --git a/playground/benchmark.R b/playground/benchmark.R deleted file mode 100644 index 7693a5de..00000000 --- a/playground/benchmark.R +++ /dev/null @@ -1,49 +0,0 @@ -library(epiworldR) -library(epiworldRfaster) - -library(microbenchmark) - - -sir <- epiworldR::ModelSEIRCONN( - name = "COVID-19", - prevalence = 0.01, - n = 100000, - contact_rate = 4, - incubation_days = 7, - transmission_rate = 0.6, - recovery_rate = 0.5 -) |> - epiworldR::add_virus( - epiworldR::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .2 - ) |> - epiworldR::verbose_off() - - -sirfast <- epiworldRfaster::ModelSEIRCONN( - name = "COVID-19", - prevalence = 0.01, - n = 100000, - contact_rate = 4, - incubation_days = 7, - transmission_rate = 0.6, - recovery_rate = 0.5 -) |> - epiworldRfaster::add_virus( - epiworldRfaster::virus("COVID-19-beta", 0.01, 0.6, 0.5, 7), .5 - ) |> - epiworldRfaster::verbose_off() - - - -res <- microbenchmark( - old = epiworldR::run(sir, ndays = 100, seed = 1912), - new = epiworldRfaster::run(sirfast, ndays = 100, seed = 1912), - times = 10 -) - -res -summary(sirfast) -summary(sir) - -boxplot(res) -