-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
88 lines (67 loc) · 1.99 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# blazr <a href="https://r-staceans.github.io/blazr/"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/r-staceans/blazr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-staceans/blazr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-staceans/blazr/graph/badge.svg)](https://app.codecov.io/gh/r-staceans/blazr)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
⚠️ **This package is a work in progress and is not yet ready for use.**
The goal of blazr is to provide R with a blazingly fast interface to multi-threading in Rust.
## Installation
Install the development version of `blazr` from GitHub with:
``` r
# install.packages("pak")
pak::pak("r-staceans/blazr")
```
## Example
Here's a simple example, computing the sum of a vector of integers, using multiple threads:
```{r example}
library(blazr)
create_int_vector <- function(n) {
set.seed(42)
sample.int(100, n, replace = TRUE)
}
n <- 1e8
x <- create_int_vector(n)
blazr::sum_with_threads(
x,
n = 2L
)
```
## Benchmarking
When running this sum against very large numbers, we can see the performance benefits of using multiple threads:
```{r benchmark}
library(bench)
library(ggplot2)
results <- bench::press(
size = c(1e7, 1e8, 1e9),
{
x = create_int_vector(n)
bench::mark(
single_thread = {
blazr::sum_with_threads(
x,
n = 1L
)
},
multi_thread = {
blazr::sum_with_threads(
x,
n = 4L
)
}
)
})
ggplot2::autoplot(results)
```