Skip to content

Commit

Permalink
updates vig
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowosad committed Feb 27, 2024
1 parent 1b9457d commit e6206ee
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 122 deletions.
227 changes: 105 additions & 122 deletions vignettes/articles/benchmarks.Rmd
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
---
title: "Benchmarks of the supercells package"
author: Jakub Nowosad
date: "`r Sys.Date()`"
date: "2024-02-27"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Benchmarks of the supercells package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
bibliography: "`r system.file('refs.bib', package = 'supercells')`"
bibliography: "/home/jakub/R/x86_64-pc-linux-gnu-library/4.3/supercells/refs.bib"
---

```{r benchmarks-1, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 6.5#,
# fig.height = 5
)
```

```{r benchmarks-2}
#| echo = FALSE
input_files_not_exist = !all(file.exists(c("lnd_low.tif", "lnd_mid.tif", "lnd_high.tif")))
output_files_notexist = !all(file.exists(c("results_low.rds", "results_mid.rds", "results_high.rds")))
```

```{r benchmarks-3}
#| message = FALSE



```r
library(terra)
library(sf)
library(supercells)
library(bench)
```

```{r benchmarks-4}
#| eval = input_files_not_exist

```r
library(rsi)
my_point = st_sfc(st_point(c(22.850000, 54.250000)), crs = "EPSG:4326")
my_point = st_transform(my_point, crs = "EPSG:2180")
Expand All @@ -47,28 +36,26 @@ lnd_mid = disagg(lnd_low, 4)
lnd_high = disagg(lnd_mid, 8)
```

```{r benchmarks-5}
#| echo = FALSE,
#| eval = input_files_not_exist
writeRaster(lnd_low, "lnd_low.tif", overwrite = TRUE, filetype = "COG")
writeRaster(lnd_mid, "lnd_mid.tif", overwrite = TRUE, filetype = "COG")
writeRaster(lnd_high, "lnd_high.tif", overwrite = TRUE, filetype = "COG")
```

```{r benchmarks-6}
#| echo = FALSE
lnd_low = rast("lnd_low.tif")
lnd_mid = rast("lnd_mid.tif")
lnd_high = rast("lnd_high.tif")
```

```{r benchmarks-7}



```r
lnd_low
#> class : SpatRaster
#> dimensions : 333, 333, 8 (nrow, ncol, nlyr)
#> resolution : 30, 30 (x, y)
#> extent : 745716.1, 755706.1, 711383.8, 721373.8 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRF2000-PL / CS92 (EPSG:2180)
#> source : lnd_low.tif
#> names : A, B, G, R, N, S1, ...
#> min values : -0.00237125, 0.006140, 0.0142250, 0.0096875, 0.0335025, 0.01516, ...
#> max values : 0.09818250, 0.112455, 0.1661212, 0.2097775, 0.5576800, 0.41105, ...
```

```{r benchmarks-8}
#| eval = output_files_notexist,
#| warning = FALSE

```r
results_low = bench::press(
step = c(10, 30, 100),
clean = c(TRUE, FALSE),
Expand All @@ -82,28 +69,46 @@ results_low = bench::press(
)
```

```{r benchmarks-9}
#| eval = output_files_notexist,
#| echo = FALSE
saveRDS(results_low, "results_low.rds")
```

```{r benchmarks-10}
#| echo = FALSE
results_low = readRDS("results_low.rds")
```

```{r benchmarks-11}
results_low
```

```{r benchmarks-12}


```r
results_low
#> # A tibble: 12 × 9
#> expression step clean iter min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <lgl> <dbl> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 s 10 TRUE 1 267ms 382.88ms 2.68 62.2MB 8.85
#> 2 s 30 TRUE 1 194ms 328.96ms 3.24 57.6MB 9.08
#> 3 s 100 TRUE 1 179ms 196.08ms 4.28 56.7MB 9.85
#> 4 s 10 FALSE 1 524ms 569.85ms 1.67 82.1MB 6.53
#> 5 s 30 FALSE 1 238ms 319.95ms 3.16 60.8MB 7.59
#> 6 s 100 FALSE 1 175ms 177.26ms 4.92 57.5MB 8.86
#> 7 s 10 TRUE 10 637ms 664.22ms 1.46 60.1MB 2.78
#> 8 s 30 TRUE 10 572ms 585.1ms 1.56 57.7MB 2.96
#> 9 s 100 TRUE 10 490ms 505.76ms 1.80 56.8MB 3.78
#> 10 s 10 FALSE 10 916ms 1.03s 0.990 82.4MB 3.86
#> 11 s 30 FALSE 10 624ms 644.35ms 1.47 61.1MB 2.79
#> 12 s 100 FALSE 10 476ms 486.17ms 2.00 57.9MB 3.40
```


```r
lnd_mid
#> class : SpatRaster
#> dimensions : 1332, 1332, 8 (nrow, ncol, nlyr)
#> resolution : 7.5, 7.5 (x, y)
#> extent : 745716.1, 755706.1, 711383.8, 721373.8 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRF2000-PL / CS92 (EPSG:2180)
#> source : lnd_mid.tif
#> names : A, B, G, R, N, S1, ...
#> min values : -0.00237125, 0.006140, 0.0142250, 0.0096875, 0.0335025, 0.01516, ...
#> max values : 0.09818250, 0.112455, 0.1661212, 0.2097775, 0.5576800, 0.41105, ...
```

```{r benchmarks-13}
#| eval = output_files_notexist,
#| warning = FALSE

```r
results_mid = bench::press(
step = c(10, 30, 100),
clean = c(TRUE, FALSE),
Expand All @@ -117,97 +122,75 @@ results_mid = bench::press(
)
```

```{r benchmarks-14}
#| eval = output_files_notexist,
#| echo = FALSE
saveRDS(results_mid, "results_mid.rds")
```

```{r benchmarks-15}
#| echo = FALSE
results_mid = readRDS("results_mid.rds")
```

```{r benchmarks-16}
results_mid
```

```{r benchmarks-17}


```r
results_mid
#> # A tibble: 12 × 9
#> expression step clean iter min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <lgl> <dbl> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 s 10 TRUE 1 3.64s 3.8s 0.262 936.35MB 1.54
#> 2 s 30 TRUE 1 2.53s 2.6s 0.380 908.11MB 1.75
#> 3 s 100 TRUE 1 2.49s 2.72s 0.370 902.22MB 2.41
#> 4 s 10 FALSE 1 8.86s 9.15s 0.108 1.36GB 1.94
#> 5 s 30 FALSE 1 2.48s 2.67s 0.371 949.17MB 1.41
#> 6 s 100 FALSE 1 1.79s 2.13s 0.471 906.74MB 1.84
#> 7 s 10 TRUE 10 10.99s 11.05s 0.0904 940.44MB 0.443
#> 8 s 30 TRUE 10 9.62s 9.75s 0.103 909.09MB 0.329
#> 9 s 100 TRUE 10 9.37s 9.48s 0.106 902.34MB 0.327
#> 10 s 10 FALSE 10 15.9s 16.58s 0.0604 1.37GB 1.33
#> 11 s 30 FALSE 10 9.82s 9.87s 0.101 951.88MB 0.456
#> 12 s 100 FALSE 10 8.57s 9.02s 0.111 907.1MB 0.411
```


```r
lnd_high
#> class : SpatRaster
#> dimensions : 10656, 10656, 8 (nrow, ncol, nlyr)
#> resolution : 0.9375, 0.9375 (x, y)
#> extent : 745716.1, 755706.1, 711383.8, 721373.8 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRF2000-PL / CS92 (EPSG:2180)
#> source : lnd_high.tif
#> names : A, B, G, R, N, S1, ...
#> min values : -0.00237125, 0.006140, 0.0142250, 0.0096875, 0.0335025, 0.01516, ...
#> max values : 0.09818250, 0.112455, 0.1661212, 0.2097775, 0.5576800, 0.41105, ...
```

```{r benchmarks-18}
#| eval = output_files_notexist,
#| warning = FALSE

```r
results_high = bench::mark(
s = supercells(lnd_high, compactness = 1, step = 30, clean = FALSE, iter = 1),
iterations = 10
)
```

```{r benchmarks-19}
#| eval = output_files_notexist,
#| echo = FALSE
saveRDS(results_high, "results_high.rds")
```

```{r benchmarks-20}
#| echo = FALSE
results_high = readRDS("results_high.rds")
```

```{r benchmarks-21}



```r
results_high
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 s 3.54m 3.61m 0.00432 59.7GB 0.214
```

<!-- If you are benchmarking parallel code you must set `memory = FALSE`. -->

```{r benchmarks-22}
#| echo = FALSE,
#| eval = FALSE,
#| warning = FALSE
results_high_chunks = bench::mark(
s = supercells(lnd_high, compactness = 1, step = 30, clean = FALSE, iter = 1,
chunks = 1000, future = FALSE),
iterations = 10, memory = FALSE
)
results_high_chunks
```

```{r benchmarks-23}
#| echo = FALSE,
#| eval = FALSE
saveRDS(results_high_chunks, "results_high_chunks.rds")
```

```{r benchmarks-24}
#| echo = FALSE,
#| eval = FALSE
readRDS("results_high_chunks.rds")
```

```{r benchmarks-25}
#| echo = FALSE,
#| eval = FALSE,
#| warning = FALSE
library(future)
plan(multisession, workers = 16)
results_high_parallel = bench::mark(
s = supercells(lnd_high, compactness = 1, step = 30, clean = FALSE, iter = 1,
chunks = 1000, future = TRUE),
iterations = 10, memory = FALSE
)
results_high_parallel
```

```{r benchmarks-26}
#| echo = FALSE,
#| eval = FALSE
saveRDS(results_high_parallel, "results_high_parallel.rds")
```

```{r benchmarks-27}
#| echo = FALSE,
#| eval = FALSE
readRDS("results_high_parallel.rds")
```






Loading

0 comments on commit e6206ee

Please sign in to comment.