23.3 Microbenchmarking
Measurement of the performance of a very small piece of code is useful for comparing small snippets of code for specific tasks.

Figure 23.2: Credits: Google search-engine
The {bench} package uses a high precision time.
bench::mark()
library(bench)
x <- runif(100)
(lb <- bench::mark(
sqrt(x),
x ^ 0.5
))
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 sqrt(x) 371.13ns 411.06ns 2181279. 848B 218.
#> 2 x^0.5 1.96µs 2.02µs 487012. 848B 0
- heavily right-skewed distribution