diff --git a/.github/stale.yml b/.github/stale.yml index 404baf0..a2d93b9 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -6,6 +6,7 @@ daysUntilClose: 7 exemptLabels: - bug - security + - not-stale # Label to use when marking an issue as stale staleLabel: stale # Comment to post when marking an issue as stale. Set to `false` to disable diff --git a/Cargo.toml b/Cargo.toml index 882ea80..e0b7388 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ name = "bincode" version = "2.0.0-dev" # remember to update html_root_url and bincode_derive authors = ["Ty Overby ", "Francesco Mazzoli ", "Zoey Riordan ", "Victor Koenders "] -exclude = ["logo.png", "examples/*", ".gitignore", ".github/"] +exclude = ["logo.svg", "examples/*", ".gitignore", ".github/"] publish = true @@ -38,7 +38,16 @@ serde = { version = "1.0.130", optional = true } serde_derive = "1.0.130" serde_json = "1.0.68" tempfile = "3.2.0" +criterion = "0.3" +rand = "0.8" +[[bench]] +name = "varint" +harness = false + +[profile.bench] +codegen-units = 1 +debug = 1 [package.metadata.docs.rs] all-features = true diff --git a/README.md b/README.md index fda97ca..a0a68e0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # Bincode - + ![CI](https://github.com/bincode-org/bincode/workflows/CI/badge.svg) [![](https://meritbadge.herokuapp.com/bincode)](https://crates.io/crates/bincode) [![](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) -[![](https://img.shields.io/badge/bincode-rustc_1.41.1+-lightgray.svg)](https://blog.rust-lang.org/2020/02/27/Rust-1.41.1.html) + +[![Matrix](https://img.shields.io/matrix/bincode:matrix.org?label=Matrix%20Chat)](https://matrix.to/#/#bincode:matrix.org) A compact encoder / decoder pair that uses a binary zero-fluff encoding scheme. The size of the encoded object will be the same or smaller than the size that @@ -109,4 +110,4 @@ maximum size limit. Malicious inputs will fail upon deserialization. ### What is Bincode's MSRV (minimum supported Rust version)? -Bincode 2.0 maintains support for Rust 1.41.1. Any changes to this are considered a breaking change for semver purposes. +Bincode 2.0 is still in development and does not yet have a targetted MSRV. Once 2.0 is fully released the MSRV will be locked. After this point any changes to the MSRV are considered a breaking change for semver purposes. diff --git a/benches/varint.rs b/benches/varint.rs new file mode 100644 index 0000000..fcaf998 --- /dev/null +++ b/benches/varint.rs @@ -0,0 +1,153 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +use bincode::config::Configuration; +use rand::distributions::Distribution; + +fn slice_varint_u8(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u8::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("slice_varint_u8", |b| { + b.iter(|| { + let _: Vec = bincode::decode_with_config(&bytes, config).unwrap(); + }) + }); +} + +fn slice_varint_u16(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u16::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("slice_varint_u16", |b| { + b.iter(|| { + let _: Vec = bincode::decode_with_config(&bytes, config).unwrap(); + }) + }); +} + +fn slice_varint_u32(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u32::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("slice_varint_u32", |b| { + b.iter(|| { + let _: Vec = bincode::decode_with_config(&bytes, config).unwrap(); + }) + }); +} + +fn slice_varint_u64(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u64::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("slice_varint_u64", |b| { + b.iter(|| { + let _: Vec = bincode::decode_with_config(&bytes, config).unwrap(); + }) + }); +} + +fn bufreader_varint_u8(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u8::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("bufreader_varint_u8", |b| { + b.iter(|| { + let _: Vec = + bincode::decode_from_with_config(&mut std::io::BufReader::new(&bytes[..]), config) + .unwrap(); + }) + }); +} + +fn bufreader_varint_u16(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u16::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("bufreader_varint_u16", |b| { + b.iter(|| { + let _: Vec = + bincode::decode_from_with_config(&mut std::io::BufReader::new(&bytes[..]), config) + .unwrap(); + }) + }); +} + +fn bufreader_varint_u32(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u32::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("bufreader_varint_u32", |b| { + b.iter(|| { + let _: Vec = + bincode::decode_from_with_config(&mut std::io::BufReader::new(&bytes[..]), config) + .unwrap(); + }) + }); +} + +fn bufreader_varint_u64(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let dist = rand::distributions::Uniform::from(0..u64::MAX); + let input: Vec = std::iter::from_fn(|| Some(dist.sample(&mut rng))) + .take(10_000) + .collect(); + let config = Configuration::standard(); + let bytes = bincode::encode_to_vec_with_config(&input, config).unwrap(); + + c.bench_function("bufreader_varint_u64", |b| { + b.iter(|| { + let _: Vec = + bincode::decode_from_with_config(&mut std::io::BufReader::new(&bytes[..]), config) + .unwrap(); + }) + }); +} + +criterion_group!( + benches, + slice_varint_u8, + slice_varint_u16, + slice_varint_u32, + slice_varint_u64, + bufreader_varint_u8, + bufreader_varint_u16, + bufreader_varint_u32, + bufreader_varint_u64, +); +criterion_main!(benches); diff --git a/logo.png b/logo.png deleted file mode 100644 index b2c454d..0000000 Binary files a/logo.png and /dev/null differ diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..9960390 --- /dev/null +++ b/logo.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +