---
title: "Benchmarking the CodelistGenerator R package"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{a10_CodelistGeneratorBenchmark}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r, include = FALSE}
CDMConnector::requireEunomia("synpuf-1k", "5.3")
```

To check the performance of the CodelistGenerator package, we can use the benchmarkCodelistGenerator(). This function generates some hypothetical study codelists using various settings and times to check how long these analyses take.

We can start for example by benchmarking our mock data, which uses duckdb.

```{r, message=FALSE, warning=FALSE}
library(DBI)
library(duckdb)
library(dplyr)
library(CDMConnector)
library(CodelistGenerator)
library(visOmopResults)

# Connect to the database and create the cdm object
con <- dbConnect(duckdb(), 
                      eunomiaDir("synpuf-1k", "5.3"))
cdm <- cdmFromCon(con = con, 
                  cdmName = "Eunomia Synpuf",
                  cdmSchema   = "main",
                  writeSchema = "main", 
                  achillesSchema = "main")

timings <- benchmarkCodelistGenerator(cdm)

visOmopTable(timings,
             hide = c("variable_name", "variable_level", "strata_name", "strata_level"),
             groupColumn = "task")
```

