Skip to content

Commit

Permalink
Add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkschumacher committed Jan 12, 2020
1 parent 9e00ccc commit 78346b8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RoxygenNote: 7.0.2
Suggests:
testthat (>= 2.1.0),
sodium,
covr
covr,
openssl,
microbenchmark
URL: https://github.com/dirkschumacher/blake3
BugReports: https://github.com/dirkschumacher/blake3/issues
16 changes: 16 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ hash <- blake3_hash_raw(input)
(sodium::bin2hex(hash))
```

## Benchmark
To get an idea about the speed we hash a random string of 1 million characters and compare it to the `openssl` implementation of `sha1`, `sha2` and `md5`.
```{r}
library(openssl)
set.seed(42)
input <- charToRaw(paste0(sample(LETTERS, 1e6, replace = TRUE), collapse = ""))
microbenchmark::microbenchmark(
md5 = md5(input),
sha1 = sha1(input),
sha2 = sha2(input),
blake3 = blake3_hash_raw(input),
times = 1000
)
```


## License

MIT
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ hash <- blake3_hash_raw(input)
#> [1] "7b2fe4e871bf4dfca892e9b46ae237f55103235e635d994f351e4553aced2bee"
```

## Benchmark

To get an idea about the speed we hash a random string of 1 million
characters and compare it to the `openssl` implementation of `sha1`,
`sha2` and `md5`.

``` r
library(openssl)
set.seed(42)
input <- charToRaw(paste0(sample(LETTERS, 1e6, replace = TRUE), collapse = ""))
microbenchmark::microbenchmark(
md5 = md5(input),
sha1 = sha1(input),
sha2 = sha2(input),
blake3 = blake3_hash_raw(input),
times = 1000
)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> md5 1639.421 1762.593 2307.9394 2037.3440 2450.195 9339.925 1000
#> sha1 1178.352 1305.298 1914.2677 1611.3670 2077.104 13262.759 1000
#> sha2 2525.234 2867.456 3796.1225 3320.0170 4155.565 25155.140 1000
#> blake3 390.594 473.616 909.4756 718.8525 1086.749 20167.403 1000
```

## License

MIT

0 comments on commit 78346b8

Please sign in to comment.