Merge branch 'trunk' into feature/deserde

This commit is contained in:
Lena Hellström 2021-10-17 21:54:26 +02:00
commit 83970d29cf
6 changed files with 183 additions and 4 deletions

1
.github/stale.yml vendored
View File

@ -6,6 +6,7 @@ daysUntilClose: 7
exemptLabels: exemptLabels:
- bug - bug
- security - security
- not-stale
# Label to use when marking an issue as stale # Label to use when marking an issue as stale
staleLabel: stale staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable # Comment to post when marking an issue as stale. Set to `false` to disable

View File

@ -7,7 +7,7 @@ members = [
name = "bincode" name = "bincode"
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
authors = ["Ty Overby <ty@pre-alpha.com>", "Francesco Mazzoli <f@mazzo.li>", "Zoey Riordan <zoey@dos.cafe>", "Victor Koenders <bincode@trangar.com>"] authors = ["Ty Overby <ty@pre-alpha.com>", "Francesco Mazzoli <f@mazzo.li>", "Zoey Riordan <zoey@dos.cafe>", "Victor Koenders <bincode@trangar.com>"]
exclude = ["logo.png", "examples/*", ".gitignore", ".github/"] exclude = ["logo.svg", "examples/*", ".gitignore", ".github/"]
publish = true publish = true
@ -38,7 +38,16 @@ serde = { version = "1.0.130", optional = true }
serde_derive = "1.0.130" serde_derive = "1.0.130"
serde_json = "1.0.68" serde_json = "1.0.68"
tempfile = "3.2.0" 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] [package.metadata.docs.rs]
all-features = true all-features = true

View File

@ -1,11 +1,12 @@
# Bincode # Bincode
<img align="right" src="./logo.png" /> <img align="right" src="./logo.svg" />
![CI](https://github.com/bincode-org/bincode/workflows/CI/badge.svg) ![CI](https://github.com/bincode-org/bincode/workflows/CI/badge.svg)
[![](https://meritbadge.herokuapp.com/bincode)](https://crates.io/crates/bincode) [![](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/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) <!-- [![](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. 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 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)? ### 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.

153
benches/varint.rs Normal file
View File

@ -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<u8> = 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<u8> = 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<u16> = 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<u16> = 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<u32> = 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<u32> = 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<u64> = 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<u64> = 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<u8> = 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<u8> =
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<u16> = 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<u16> =
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<u32> = 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<u32> =
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<u64> = 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<u64> =
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);

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 KiB

15
logo.svg Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="37.239mm" height="45mm" version="1.1" viewBox="0 0 37.239 45" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(-82.272 -105)">
<path d="m103.92 150-21.651-12.5v-27l9.5263-5.5h24.249l3.4641 2v34z" fill="#fff"/>
<g transform="skewY(-30)" stroke-width=".26458" aria-label="1">
<path d="m115.85 204.23q0 1.0273-0.59267 1.62-0.59267 0.55316-1.5804 0.55316h-2.3707q-1.0273 0-1.62-0.55316-0.55316-0.59266-0.55316-1.62v-21.692q0-0.7112 0.47413-1.1458 0.47414-0.43462 0.86925-0.39511 0.39511 0 0.43462 0 0 0 0.31609 0 0.31609-0.0395 0.79022 0.39511 0.47413 0.43463 0.47413 1.1063v7.3096q0 2.0151 0.19756 2.5682 0.19755 0.55315 0.94827 1.3434l0.94826 0.90875q0.79022 0.7112 1.0273 1.3039 0.23707 0.59266 0.23707 2.6472z"/>
</g>
<g transform="skewY(30)" fill="#010101" stroke-width=".26458" aria-label="0">
<path d="m92.053 83.506q0.63218 0 1.0273 0 0.43462 0 0.63218 0 1.1458 0 1.3829-0.19756 0.27658-0.23707 0.27658-1.3039v-14.501q0-0.63218 0-1.0273 0-0.43462 0-0.63218 0-1.1853-0.23707-1.4224-0.19756-0.27658-1.2644-0.27658h-3.5165q-0.63218 0-1.0668 0-0.39511 0-0.59267 0-1.2248 0-1.4619 0.27658-0.23707 0.27658-0.23707 1.5804v14.145q0 0.43462 0 0.86924t0 0.67169q0 1.2644 0.23707 1.5409 0.23707 0.27658 1.4224 0.27658zm-8.3764 0.86924v-21.138q0-0.86924 0.63218-1.5014 0.67169-0.67169 1.5014-0.67169h10.787q0.79022 0 1.4619 0.63218 0.67169 0.63218 0.67169 1.5409v21.138q0 2.1731-2.1731 2.1731h-10.747q-2.1336 0-2.1336-2.1731z" fill="#010101"/>
</g>
<path d="m93.531 106 10.392 6 10.392-6 3.4641 2v8l-3.4641-2-6.9282 4v24l3.4641 2-6.9282 4-6.9282-4 3.4641-2v-24l-6.9282-4-3.4641 2v-8z" fill="#7137c8"/>
<path d="m103.92 116 13.856-8v8l-3.4641-2-6.9282 4v24l3.4641 2-6.9282 4z" fill="#442178"/>
<path d="m103.92 116 13.856-8-3.4641-2-10.392 6-10.392-6-3.4641 2z" fill="#8d5fd3"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB