| 1 |
diff --git a/Cargo.toml b/Cargo.toml |
| 2 |
index 0be40d9..f1540d7 100644 |
| 3 |
--- a/Cargo.toml |
| 4 |
+++ b/Cargo.toml |
| 5 |
@@ -116,21 +116,6 @@ path = "tests/std.rs" |
| 6 |
name = "utils" |
| 7 |
path = "tests/utils.rs" |
| 8 |
|
| 9 |
-[[bench]] |
| 10 |
-name = "inline" |
| 11 |
-path = "benches/inline.rs" |
| 12 |
-harness = false |
| 13 |
- |
| 14 |
-[[bench]] |
| 15 |
-name = "string" |
| 16 |
-path = "benches/string.rs" |
| 17 |
-harness = false |
| 18 |
- |
| 19 |
-[[bench]] |
| 20 |
-name = "varint" |
| 21 |
-path = "benches/varint.rs" |
| 22 |
-harness = false |
| 23 |
- |
| 24 |
[dependencies.bincode_derive] |
| 25 |
version = "2.0.1" |
| 26 |
optional = true |
| 27 |
diff --git a/benches/inline.rs b/benches/inline.rs |
| 28 |
deleted file mode 100644 |
| 29 |
index 56f5ade..0000000 |
| 30 |
--- a/benches/inline.rs |
| 31 |
+++ /dev/null |
| 32 |
@@ -1,17 +0,0 @@ |
| 33 |
-use bincode::config; |
| 34 |
-use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 35 |
- |
| 36 |
-fn inline_decoder_claim_bytes_read(c: &mut Criterion) { |
| 37 |
- let config = config::standard().with_limit::<100000>(); |
| 38 |
- let slice = bincode::encode_to_vec(vec![String::from("Hello world"); 1000], config).unwrap(); |
| 39 |
- |
| 40 |
- c.bench_function("inline_decoder_claim_bytes_read", |b| { |
| 41 |
- b.iter(|| { |
| 42 |
- let _: (Vec<String>, usize) = |
| 43 |
- black_box(bincode::decode_from_slice(black_box(&slice), config).unwrap()); |
| 44 |
- }) |
| 45 |
- }); |
| 46 |
-} |
| 47 |
- |
| 48 |
-criterion_group!(benches, inline_decoder_claim_bytes_read); |
| 49 |
-criterion_main!(benches); |
| 50 |
diff --git a/benches/string.rs b/benches/string.rs |
| 51 |
deleted file mode 100644 |
| 52 |
index f565b4a..0000000 |
| 53 |
--- a/benches/string.rs |
| 54 |
+++ /dev/null |
| 55 |
@@ -1,73 +0,0 @@ |
| 56 |
-// https://github.com/bincode-org/bincode/issues/618 |
| 57 |
- |
| 58 |
-use bincode::{Decode, Encode}; |
| 59 |
-use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 60 |
-use serde::{Deserialize, Serialize}; |
| 61 |
- |
| 62 |
-#[derive(Serialize, Deserialize, Default, Encode, Decode)] |
| 63 |
-pub struct MyStruct { |
| 64 |
- pub v: Vec<String>, |
| 65 |
- pub string: String, |
| 66 |
- pub number: usize, |
| 67 |
-} |
| 68 |
- |
| 69 |
-impl MyStruct { |
| 70 |
- #[inline] |
| 71 |
- pub fn new(v: Vec<String>, string: String, number: usize) -> Self { |
| 72 |
- Self { v, string, number } |
| 73 |
- } |
| 74 |
-} |
| 75 |
- |
| 76 |
-fn build_data(size: usize) -> Vec<MyStruct> { |
| 77 |
- (0..size) |
| 78 |
- .map(|i| { |
| 79 |
- let vec: Vec<String> = (0..i).map(|i| i.to_string().repeat(100)).collect(); |
| 80 |
- MyStruct::new(vec, size.to_string(), size) |
| 81 |
- }) |
| 82 |
- .collect() |
| 83 |
-} |
| 84 |
- |
| 85 |
-fn index_item_decode(c: &mut Criterion) { |
| 86 |
- let data = build_data(100); |
| 87 |
- |
| 88 |
- c.bench_function("bench v1", |b| { |
| 89 |
- b.iter(|| { |
| 90 |
- let _ = black_box(bincode_1::serialize(black_box(&data))).unwrap(); |
| 91 |
- }); |
| 92 |
- }); |
| 93 |
- |
| 94 |
- let config = bincode::config::standard(); |
| 95 |
- c.bench_function("bench v2 (standard)", |b| { |
| 96 |
- b.iter(|| { |
| 97 |
- let _ = black_box(bincode::encode_to_vec(black_box(&data), config)).unwrap(); |
| 98 |
- }); |
| 99 |
- }); |
| 100 |
- |
| 101 |
- let config = bincode::config::legacy(); |
| 102 |
- c.bench_function("bench v2 (legacy)", |b| { |
| 103 |
- b.iter(|| { |
| 104 |
- let _ = black_box(bincode::encode_to_vec(black_box(&data), config)).unwrap(); |
| 105 |
- }); |
| 106 |
- }); |
| 107 |
- |
| 108 |
- let encodedv1 = bincode_1::serialize(&data).unwrap(); |
| 109 |
- let encodedv2 = bincode::encode_to_vec(&data, config).unwrap(); |
| 110 |
- assert_eq!(encodedv1, encodedv2); |
| 111 |
- |
| 112 |
- c.bench_function("bench v1 decode", |b| { |
| 113 |
- b.iter(|| { |
| 114 |
- let _: Vec<MyStruct> = |
| 115 |
- black_box(bincode_1::deserialize(black_box(&encodedv1))).unwrap(); |
| 116 |
- }); |
| 117 |
- }); |
| 118 |
- |
| 119 |
- c.bench_function("bench v2 decode (legacy)", |b| { |
| 120 |
- b.iter(|| { |
| 121 |
- let _: (Vec<MyStruct>, _) = |
| 122 |
- black_box(bincode::decode_from_slice(black_box(&encodedv1), config)).unwrap(); |
| 123 |
- }); |
| 124 |
- }); |
| 125 |
-} |
| 126 |
- |
| 127 |
-criterion_group!(benches, index_item_decode); |
| 128 |
-criterion_main!(benches); |
| 129 |
diff --git a/benches/varint.rs b/benches/varint.rs |
| 130 |
deleted file mode 100644 |
| 131 |
index 248ab0a..0000000 |
| 132 |
--- a/benches/varint.rs |
| 133 |
+++ /dev/null |
| 134 |
@@ -1,152 +0,0 @@ |
| 135 |
-use bincode::config; |
| 136 |
-use criterion::{criterion_group, criterion_main, Criterion}; |
| 137 |
-use rand::distributions::Distribution; |
| 138 |
- |
| 139 |
-fn slice_varint_u8(c: &mut Criterion) { |
| 140 |
- let mut rng = rand::thread_rng(); |
| 141 |
- let dist = rand::distributions::Uniform::from(0..u8::MAX); |
| 142 |
- let input: Vec<u8> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 143 |
- .take(10_000) |
| 144 |
- .collect(); |
| 145 |
- let config = config::standard(); |
| 146 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 147 |
- |
| 148 |
- c.bench_function("slice_varint_u8", |b| { |
| 149 |
- b.iter(|| { |
| 150 |
- let _: (Vec<u8>, usize) = bincode::decode_from_slice(&bytes, config).unwrap(); |
| 151 |
- }) |
| 152 |
- }); |
| 153 |
-} |
| 154 |
- |
| 155 |
-fn slice_varint_u16(c: &mut Criterion) { |
| 156 |
- let mut rng = rand::thread_rng(); |
| 157 |
- let dist = rand::distributions::Uniform::from(0..u16::MAX); |
| 158 |
- let input: Vec<u16> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 159 |
- .take(10_000) |
| 160 |
- .collect(); |
| 161 |
- let config = config::standard(); |
| 162 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 163 |
- |
| 164 |
- c.bench_function("slice_varint_u16", |b| { |
| 165 |
- b.iter(|| { |
| 166 |
- let _: (Vec<u16>, usize) = bincode::decode_from_slice(&bytes, config).unwrap(); |
| 167 |
- }) |
| 168 |
- }); |
| 169 |
-} |
| 170 |
- |
| 171 |
-fn slice_varint_u32(c: &mut Criterion) { |
| 172 |
- let mut rng = rand::thread_rng(); |
| 173 |
- let dist = rand::distributions::Uniform::from(0..u32::MAX); |
| 174 |
- let input: Vec<u32> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 175 |
- .take(10_000) |
| 176 |
- .collect(); |
| 177 |
- let config = config::standard(); |
| 178 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 179 |
- |
| 180 |
- c.bench_function("slice_varint_u32", |b| { |
| 181 |
- b.iter(|| { |
| 182 |
- let _: (Vec<u32>, usize) = bincode::decode_from_slice(&bytes, config).unwrap(); |
| 183 |
- }) |
| 184 |
- }); |
| 185 |
-} |
| 186 |
- |
| 187 |
-fn slice_varint_u64(c: &mut Criterion) { |
| 188 |
- let mut rng = rand::thread_rng(); |
| 189 |
- let dist = rand::distributions::Uniform::from(0..u64::MAX); |
| 190 |
- let input: Vec<u64> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 191 |
- .take(10_000) |
| 192 |
- .collect(); |
| 193 |
- let config = config::standard(); |
| 194 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 195 |
- |
| 196 |
- c.bench_function("slice_varint_u64", |b| { |
| 197 |
- b.iter(|| { |
| 198 |
- let _: (Vec<u64>, usize) = bincode::decode_from_slice(&bytes, config).unwrap(); |
| 199 |
- }) |
| 200 |
- }); |
| 201 |
-} |
| 202 |
- |
| 203 |
-fn bufreader_varint_u8(c: &mut Criterion) { |
| 204 |
- let mut rng = rand::thread_rng(); |
| 205 |
- let dist = rand::distributions::Uniform::from(0..u8::MAX); |
| 206 |
- let input: Vec<u8> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 207 |
- .take(10_000) |
| 208 |
- .collect(); |
| 209 |
- let config = config::standard(); |
| 210 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 211 |
- |
| 212 |
- c.bench_function("bufreader_varint_u8", |b| { |
| 213 |
- b.iter(|| { |
| 214 |
- let _: Vec<u8> = |
| 215 |
- bincode::decode_from_reader(&mut std::io::BufReader::new(&bytes[..]), config) |
| 216 |
- .unwrap(); |
| 217 |
- }) |
| 218 |
- }); |
| 219 |
-} |
| 220 |
- |
| 221 |
-fn bufreader_varint_u16(c: &mut Criterion) { |
| 222 |
- let mut rng = rand::thread_rng(); |
| 223 |
- let dist = rand::distributions::Uniform::from(0..u16::MAX); |
| 224 |
- let input: Vec<u16> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 225 |
- .take(10_000) |
| 226 |
- .collect(); |
| 227 |
- let config = config::standard(); |
| 228 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 229 |
- |
| 230 |
- c.bench_function("bufreader_varint_u16", |b| { |
| 231 |
- b.iter(|| { |
| 232 |
- let _: Vec<u16> = |
| 233 |
- bincode::decode_from_reader(&mut std::io::BufReader::new(&bytes[..]), config) |
| 234 |
- .unwrap(); |
| 235 |
- }) |
| 236 |
- }); |
| 237 |
-} |
| 238 |
- |
| 239 |
-fn bufreader_varint_u32(c: &mut Criterion) { |
| 240 |
- let mut rng = rand::thread_rng(); |
| 241 |
- let dist = rand::distributions::Uniform::from(0..u32::MAX); |
| 242 |
- let input: Vec<u32> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 243 |
- .take(10_000) |
| 244 |
- .collect(); |
| 245 |
- let config = config::standard(); |
| 246 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 247 |
- |
| 248 |
- c.bench_function("bufreader_varint_u32", |b| { |
| 249 |
- b.iter(|| { |
| 250 |
- let _: Vec<u32> = |
| 251 |
- bincode::decode_from_reader(&mut std::io::BufReader::new(&bytes[..]), config) |
| 252 |
- .unwrap(); |
| 253 |
- }) |
| 254 |
- }); |
| 255 |
-} |
| 256 |
- |
| 257 |
-fn bufreader_varint_u64(c: &mut Criterion) { |
| 258 |
- let mut rng = rand::thread_rng(); |
| 259 |
- let dist = rand::distributions::Uniform::from(0..u64::MAX); |
| 260 |
- let input: Vec<u64> = std::iter::from_fn(|| Some(dist.sample(&mut rng))) |
| 261 |
- .take(10_000) |
| 262 |
- .collect(); |
| 263 |
- let config = config::standard(); |
| 264 |
- let bytes = bincode::encode_to_vec(input, config).unwrap(); |
| 265 |
- |
| 266 |
- c.bench_function("bufreader_varint_u64", |b| { |
| 267 |
- b.iter(|| { |
| 268 |
- let _: Vec<u64> = |
| 269 |
- bincode::decode_from_reader(&mut std::io::BufReader::new(&bytes[..]), config) |
| 270 |
- .unwrap(); |
| 271 |
- }) |
| 272 |
- }); |
| 273 |
-} |
| 274 |
- |
| 275 |
-criterion_group!( |
| 276 |
- benches, |
| 277 |
- slice_varint_u8, |
| 278 |
- slice_varint_u16, |
| 279 |
- slice_varint_u32, |
| 280 |
- slice_varint_u64, |
| 281 |
- bufreader_varint_u8, |
| 282 |
- bufreader_varint_u16, |
| 283 |
- bufreader_varint_u32, |
| 284 |
- bufreader_varint_u64, |
| 285 |
-); |
| 286 |
-criterion_main!(benches); |