Skip to content

Commit

Permalink
Move perftest to workspace root (#113)
Browse files Browse the repository at this point in the history
* move perftest to workspace root

* update readmes

* fix read_file bench

* rustfmt
  • Loading branch information
tafia committed Aug 16, 2018
1 parent 8e9b542 commit 0806187
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -3,5 +3,5 @@
members = [
"quick-protobuf",
"pb-rs",
"quick-protobuf/benches/rust-protobuf",
"perftest",
]
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -250,7 +250,8 @@ Have a look at the different generated modules for the same .proto file:

#### Benchmarks

An [adaptation of rust-protobuf perftest](quick-protobuf/benches/rust-protobuf) is available and show, on these particular examples, that quick-protobuf is much faster than rust-protobuf.
See [perftest](perftest), an adaptation of rust protobuf's perftest. Depending on your scenario each crate has its merit.
quick-protobuf is particularly good at reading large bytes.

## Contribution

Expand Down
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@ build = "build.rs"

[dependencies]
protobuf = "2.0.4"
quick-protobuf = { path = "../../" }
quick-protobuf = { path = "../quick-protobuf" }
time = "0.1.40"
rand = "0.5.5"
prost = "0.4.0"
Expand All @@ -16,5 +16,5 @@ bytes = "0.4.9"

[build-dependencies]
protobuf-codegen-pure = "2.0.4"
pb-rs = { path = "../../../pb-rs" }
pb-rs = { path = "../pb-rs" }
prost-build = "0.4.0"
68 changes: 68 additions & 0 deletions perftest/README.md
@@ -0,0 +1,68 @@
# perftest

The purpose of this package is to compare the performances of
- protobuf
- quick-protobuf
- prost

These tests are copied and adapted from [rust-protobuf](https://github.com/stepancheg/rust-protobuf/tree/master/src/perftest)

## Setup

Prost requires google `protoc` to be installed and available in your PATH.
For the 3 projects, all files are generated at build time.

## Results

```
labels rust-protobuf quick-protobuf prost quick/rust prost/rust
ns/iter ns/iter ns/iter % %
test1
write 72 20 21 72.2 70.8
read 71 31 53 56.3 25.4
read no vec 44 20 46 54.5 -4.5
read reuse 42 NA NA
test_repeated_bool
write 80 33 28 58.8 65.0
read 167 114 147 31.7 12.0
read no vec 124 79 123 36.3 0.8
read reuse 62 NA NA
test_repeated_packed_int32
write 135 69 46 48.9 65.9
read 241 186 216 22.8 10.4
read no vec 182 152 180 16.5 1.1
read reuse 71 NA NA
test_repeated_messages
write 213 178 227 16.4 -6.6
read 665 550 519 17.3 22.0
read no vec 384 380 353 1.0 8.1
read reuse 169 NA NA
test_optional_messages
write 223 157 104 29.6 53.4
read 515 316 313 38.6 39.2
read no vec 354 241 249 31.9 29.7
read reuse 191 NA NA
test_strings
write 146 63 59 56.8 59.6
read 345 185 247 46.4 28.4
read no vec 234 87 178 62.8 23.9
read reuse 124 NA NA
test_small_bytearrays
write 479 463 318 3.3 33.6
read 747 99 729 86.7 2.4
read no vec 182 31 259 83.0 -42.3
read reuse 113 NA NA
test_large_bytearrays
write 109299 96753 89523 11.5 18.1
read 47513 8598 66959 81.9 -40.9
read no vec 11245 56 9641 99.5 14.3
read reuse 8834 NA NA
```
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,13 +7,11 @@ extern crate time;
#[macro_use]
extern crate prost_derive;

use rand::{rngs::SmallRng, Rng, SeedableRng};
use std::default::Default;
use std::fmt::Debug;
use std::fs::File;
use std::io::Read;
use std::path::Path;

use rand::{rngs::SmallRng, Rng, SeedableRng};

use bytes::{Buf, IntoBuf};

Expand Down Expand Up @@ -413,15 +411,21 @@ fn main() {
data_size: data_size,
};

let mut is = File::open(&Path::new("perftest_data.pbbin")).unwrap();
let test_data = protobuf::parse_from_reader::<PerftestData>(&mut is).unwrap();
let data = {
let mut is = File::open(&format!(
"{}/{}",
env!("CARGO_MANIFEST_DIR"),
"perftest_data.pbbin"
)).unwrap();
let mut data = Vec::new();
is.read_to_end(&mut data).unwrap();
data
};

let mut reader = Reader::from_file("perftest_data.pbbin").unwrap();
let test_data = protobuf::parse_from_reader::<PerftestData>(&mut &*data).unwrap();
let mut reader = Reader::from_reader(&mut &*data, data.len()).unwrap();
let test_data_quick = reader.read(QuickPerftestData::from_reader).unwrap();

let mut is = File::open(&Path::new("perftest_data.pbbin")).unwrap();
let mut data = Vec::new();
is.read_to_end(&mut data).unwrap();
let test_data_prost = perftest_data_prost::PerftestData::decode(&data).unwrap();

let a = runner.test(test_data.get_test1());
Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions quick-protobuf/README.md
Expand Up @@ -213,16 +213,6 @@ This library is an alternative to the widely used [rust-protobuf](https://github
- Not a drop-in replacement of rust-protobuf
- everything being explicit you have to handle more things yourself (e.g. `Option` unwrapping, `Cow` management)

#### Codegen

Have a look at the different generated modules for the same .proto file:
- [rust-protobuf](https://github.com/tafia/quick-protobuf/blob/master/benches/rust-protobuf/perftest_data.rs): 2371 loc
- [quick-protobuf](https://github.com/tafia/quick-protobuf/blob/master/benches/rust-protobuf/perftest_data_quick.rs): 302 loc

#### Benchmarks

An [adaptation of rust-protobuf perftest](benches/rust-protobuf) is available and show, on these particular examples, that quick-protobuf is much faster than rust-protobuf.

## Contribution

Any help is welcomed! (Pull requests of course, bug report, missing functionality etc...)
Expand Down
6 changes: 5 additions & 1 deletion quick-protobuf/benches/perftest.rs
Expand Up @@ -17,8 +17,12 @@ use test::{black_box, Bencher};

#[bench]
fn read_file(b: &mut Bencher) {
let path = format!(
"{}/benches/perftest_data/perftest_data.pbbin",
env!("CARGO_MANIFEST_DIR")
);
b.iter(|| {
let mut reader = Reader::from_file("benches/rust-protobuf/perftest_data.pbbin").unwrap();
let mut reader = Reader::from_file(&path).unwrap();
reader.read(PerftestData::from_reader).unwrap().test1.len()
})
}
Expand Down
Binary file not shown.
64 changes: 0 additions & 64 deletions quick-protobuf/benches/rust-protobuf/README.md

This file was deleted.

0 comments on commit 0806187

Please sign in to comment.