Benchmark for a model that can also be solved with Eigenvalues

This evaluation is taken from the example section of mkinfit. When using an mkin version greater or equal than 0.9-36 and the C++ compiler g++ is installed and functional (on Windows, install Rtools), you will get a message that the model is being compiled when defining a model using mkinmod.

library("mkin")
SFO_SFO <- mkinmod(
  parent = list(type = "SFO", to = "m1", sink = TRUE),
  m1 = list(type = "SFO"), odeintr_compile = "yes")
## Compiling differential equation model from auto-generated C++ code...

We can compare the performance of the Eigenvalue based solution against the compiled version and the R implementation of the differential equations using the microbenchmark package.

smb.1 <- summary(mb.1)[-1]
rownames(smb.1) <- c("deSolve, not compiled", "Eigenvalue based", "odeintr, compiled")
print(smb.1)
##                             min        lq      mean    median        uq
## deSolve, not compiled 5254.1030 5261.3501 5277.1074 5268.5973 5288.6096
## Eigenvalue based       897.1575  921.6935  930.9546  946.2296  947.8531
## odeintr, compiled      693.6001  709.0719  719.5530  724.5438  732.5295
##                             max neval
## deSolve, not compiled 5308.6218     3
## Eigenvalue based       949.4766     3
## odeintr, compiled      740.5151     3

We see that using the compiled model is more than a factor of 7 faster than using the R version with the default ode solver, and it is even faster than the Eigenvalue based solution implemented in R which does not need iterative solution of the ODEs:

smb.1["median"]/smb.1["odeintr, compiled", "median"]
##                         median
## deSolve, not compiled 7.290796
## Eigenvalue based      1.370242
## odeintr, compiled     1.000000

Benchmark for a model that can not be solved with Eigenvalues

This evaluation is also taken from the example section of mkinfit.

FOMC_SFO <- mkinmod(
  parent = list(type = "FOMC", to = "m1", sink = TRUE),
  m1 = list(type = "SFO"))
## Compiling differential equation model from auto-generated C++ code...
mb.2 <- microbenchmark(
  mkinfit(FOMC_SFO, FOCUS_2006_D, solution_type = "deSolve", quiet = TRUE),
  mkinfit(FOMC_SFO, FOCUS_2006_D, solution_type = "odeintr", quiet = TRUE),
  times = 3, control = list(warmup = 1))
smb.2 <- summary(mb.2)[-1]
rownames(smb.2) <- c("deSolve, not compiled", "odeintr, compiled")
print(smb.2)
##                             min        lq      mean    median        uq
## deSolve, not compiled 11.243675 11.324875 11.382415 11.406074 11.451785
## odeintr, compiled      1.207114  1.209908  1.239989  1.212703  1.256426
##                             max neval
## deSolve, not compiled 11.497496     3
## odeintr, compiled      1.300149     3
smb.2["median"]/smb.2["odeintr, compiled", "median"]
##                         median
## deSolve, not compiled 9.405494
## odeintr, compiled     1.000000

Here we get a performance benefit of more than a factor of 8 using the version of the differential equation model compiled from C++ code using the odeintr package!