---
title: "Benchmarking slopes calculation"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Benchmarking slopes calculation}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

```{r setup}
library(slopes)
library(bench)
```

# Performance

A benchmark can reveal how many route gradients can be calculated per second
using different interpolation methods:

```{r, results='hide'}
e = dem_lisbon()
r = lisbon_road_network
res = bench::mark(check = FALSE,
  bilinear = slope_raster(r, e),
  simple   = slope_raster(r, e, method = "simple")
)
```

```{r}
res
```


That is approximately

```{r}
round(res$`itr/sec` * nrow(r))
```

routes per second using `bilinear` and `simple` interpolation methods, respectively.

To go faster, you can chose the `simple` method to gain some speed at the expense of accuracy:

```{r, results='hide'}
res2 = bench::mark(check = FALSE,
  bilinear = slope_raster(r, e, method = "bilinear"),
  simple   = slope_raster(r, e, method = "simple")
)
```

```{r}
res2
```

```{r}
round(res2$`itr/sec` * nrow(r))
```
