-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated Themis Core benchmarks (#580)
* Themis Core benchmarks Let's add some reproducible, verifiable, and automatable benchmarks for Themis performance. We are using Criterion.rs -- a framework in Rust -- but since C is easily callable from Rust, it's not much an issue to use that framework for accurately benchmarking C code. And I don't have to reinvent the wheel and build a benchmarking harness myself as it is usually done in C/C++ world. Currently we cover Secure Cell in Seal mode with master key. More benches will come in later, this is only an example and a primer. We exercise both encryption and decryption code paths. The data does not really matter so we use whatever is easy to get. Message size comparison confirms that encryption and decryption have roughly the same cost and indeed have linear complexity. * Run benchmarks on CI Do this for every build, at least to check that they are still buildable. Also run some of them for a modest amount of time and attach benchmark reports to builds. It would be nice to compare base branch with PR branch to see if there are any changes in that. However, with current approach branch switching is kinda involved so we'll add that later.
- Loading branch information
Showing
8 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ⏱ Themis benchmarks | ||
|
||
Here you can find benchmarks used to measure overhead and performance of Themis and its wrappers. | ||
|
||
## 👾 Themis Core | ||
|
||
These are the main benchmarks for Themis. | ||
They establish a baseline for perfomance: | ||
high-level language wrappers generally add overhead to Core. | ||
|
||
See [`themis`](themis) directory for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Criterion output | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "themis-core-bench" | ||
version = "0.0.0" | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
themis = { version = "0.12", path = "../../src/wrappers/themis/rust" } | ||
libthemis-sys = { version = "0.12", path = "../../src/wrappers/themis/rust/libthemis-sys" } | ||
|
||
[dev-dependencies] | ||
criterion = "0.3" | ||
|
||
[[bench]] | ||
name = "secure_cell_seal_master_key" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# ⏱ Themis Core benchmarks | ||
|
||
## Quickstart | ||
|
||
Themis Core benchmarks are written using [**Criterion.rs**](https://bheisler.github.io/criterion.rs/book/criterion_rs.html) statistical benchmarking tool. | ||
|
||
You will need Rust toolchain installed to run benchmarks. | ||
[Visit rustup.rs](https://rustup.rs/) to install Rust. | ||
|
||
1. 📦 **Install Themis Core** | ||
|
||
Benchmarks use Themis library from the system by default. | ||
<!-- TODO: use local builds if available --> | ||
|
||
Normally, this should be enough to install Themis: | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
If it doesn’t work (or this is your first time building Themis) | ||
then you might need to [review the documentation](https://docs.cossacklabs.com/pages/documentation-themis/#building-and-installing). | ||
|
||
If it still doesn’t work, please [file an issue](https://github.com/cossacklabs/themis/issues/new?labels=bug,installation,core&template=bug_report.md&title=). | ||
|
||
2. ⚙️ **Change directory from repository root** | ||
|
||
```bash | ||
cd benches/themis | ||
``` | ||
|
||
It’s not required but you would have to type less. | ||
|
||
3. ⏳ **Build dependencies** | ||
|
||
```bash | ||
cargo bench --no-run | ||
``` | ||
|
||
Criterion.rs has quite a few dependencies so be patient, | ||
you need to do this only once. | ||
|
||
4. 🚀 **Run some benchmarks** | ||
|
||
```bash | ||
cargo bench -- "Secure Cell .* Seal, master key/64 KB" | ||
``` | ||
|
||
[See FAQ](#faq) for more information on how and what you can run. | ||
|
||
5. 📊 **Analyze result report** | ||
|
||
```bash | ||
open target/criterion/report/index.html | ||
``` | ||
|
||
Done! 🎉 | ||
|
||
## Coverage | ||
|
||
### Secure Cell | ||
|
||
| | Master keys | Passphrases | | ||
| ----------------- | ------------- | ------------- | | ||
| Seal | ✅ complete | 🛠 WIP | | ||
| Token Protect | 💭 soon | 🛠 WIP | | ||
| Context Imprint | 💭 soon | ➖ N/A | | ||
|
||
### Secure Message | ||
|
||
| | ECDSA | RSA | | ||
| ----------------- | ------------- | ------------- | | ||
| Encrypt / Decrypt | 💭 soon | 💭 soon | | ||
| Sign / Verify | 💭 soon | 💭 soon | | ||
|
||
### Secure Session | ||
|
||
💭 soon | ||
|
||
### Secure Comparator | ||
|
||
💭 soon | ||
|
||
<!-- | ||
|
||
## Benchmark results | ||
|
||
TODO: describe current benchmark results here | ||
|
||
--> | ||
|
||
## FAQ | ||
|
||
First of all, it’s a good idea to familiarize yourself with | ||
[Criterion.rs User Guide](https://bheisler.github.io/criterion.rs/book/criterion_rs.html), | ||
especially sections on | ||
[command-line options](https://bheisler.github.io/criterion.rs/book/user_guide/command_line_options.html), | ||
[output format](https://bheisler.github.io/criterion.rs/book/user_guide/command_line_output.html), | ||
and [interpreting results](https://bheisler.github.io/criterion.rs/book/analysis.html). | ||
|
||
**Q:** What benchmarks are available? | ||
|
||
```bash | ||
cargo bench -- --list | ||
``` | ||
|
||
**Q:** How do I run one of them? | ||
|
||
```bash | ||
cargo bench -- 'one of them' # filter by regular expression | ||
``` | ||
|
||
**Q:** How do I see if my optimizations have an effect? | ||
|
||
```bash | ||
git checkout feature | ||
cargo bench -- --save-baseline feature-unoptimized | ||
git checkout optimizations | ||
# Work on performance | ||
# ... | ||
# Compare against the baseline version | ||
cargo bench -- --baseline feature-unoptimized | ||
``` | ||
|
||
Don’t forget to _reinstall_ Themis Core library every time you make a change in it and want to measure it. | ||
<!-- TODO: and to pester maintainers to support local builds --> | ||
|
||
**Q:** Benchmarking takes ages, what can I do? | ||
|
||
```bash | ||
cargo bench -- --sample-size 20 # cannot be lower than 10 | ||
``` |
Oops, something went wrong.