Skip to content

Commit

Permalink
Adding benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Oct 17, 2023
1 parent 7e3ae5b commit 4c912a4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
50 changes: 50 additions & 0 deletions playground/benchmark-seir.R
Original file line number Diff line number Diff line change
@@ -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")

52 changes: 52 additions & 0 deletions playground/benchmark-seirconn.R
Original file line number Diff line number Diff line change
@@ -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")

49 changes: 0 additions & 49 deletions playground/benchmark.R

This file was deleted.

0 comments on commit 4c912a4

Please sign in to comment.