Skip to content

Commit 17cb20d

Browse files
committed
Add more bench cases
1 parent b0b5359 commit 17cb20d

File tree

3 files changed

+101
-17
lines changed

3 files changed

+101
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "msgpacker"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = ["Victor Lopez <victor@codx.io>"]
55
categories = ["compression", "encoding", "parser-implementations"]
66
edition = "2021"

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,22 @@ Results obtained with `Intel(R) Core(TM) i9-9900X CPU @ 3.50GHz`
116116

117117
```ignore,no_run
118118
$ cargo bench
119-
msgpack nil time: [3.3648 ns 3.3783 ns 3.3928 ns]
120-
msgunpack nil time: [25.925 ns 26.008 ns 26.097 ns]
121-
msgunpack ref nil time: [22.632 ns 22.709 ns 22.789 ns]
122-
msgpack int time: [5.9986 ns 6.0216 ns 6.0525 ns]
123-
msgunpack int time: [25.481 ns 25.579 ns 25.680 ns]
124-
msgunpack ref int time: [22.635 ns 22.727 ns 22.830 ns]
125-
msgpack map time: [1.1588 us 1.1626 us 1.1667 us]
126-
msgunpack map time: [25.955 ns 26.045 ns 26.141 ns]
127-
msgunpack ref map time: [22.626 ns 22.716 ns 22.810 ns]
119+
msgpack nil time: [4.6849 ns 4.6898 ns 4.6961 ns]
120+
msgunpack nil time: [23.654 ns 23.675 ns 23.707 ns]
121+
msgunpack ref nil time: [20.253 ns 20.280 ns 20.318 ns]
122+
msgpack int time: [6.0831 ns 6.0921 ns 6.1045 ns]
123+
msgunpack int time: [26.375 ns 26.415 ns 26.465 ns]
124+
msgunpack ref int time: [25.163 ns 25.202 ns 25.258 ns]
125+
msgpack map 1 time: [17.411 ns 17.432 ns 17.461 ns]
126+
msgunpack map 1 time: [118.56 ns 118.67 ns 118.83 ns]
127+
msgunpack ref map 1 time: [59.850 ns 59.898 ns 59.972 ns]
128+
msgpack map 5 time: [73.763 ns 73.881 ns 74.049 ns]
129+
msgunpack map 5 time: [539.42 ns 539.91 ns 540.56 ns]
130+
msgunpack ref map 5 time: [161.39 ns 161.58 ns 161.86 ns]
131+
msgpack map 10 time: [133.03 ns 133.18 ns 133.39 ns]
132+
msgunpack map 10 time: [1.0574 us 1.0583 us 1.0597 us]
133+
msgunpack ref map 10 time: [289.05 ns 289.43 ns 289.98 ns]
134+
msgpack map 100 time: [1.2123 us 1.2135 us 1.2150 us]
135+
msgunpack map 100 time: [9.3964 us 9.4076 us 9.4214 us]
136+
msgunpack ref map 100 time: [2.6246 us 2.6283 us 2.6334 us]
128137
```

benches/pack.rs

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,35 @@ pub fn pack(c: &mut Criterion) {
66
let message_nil = Message::Nil;
77
let message_int = Message::from(i64::MIN);
88

9+
let m = MapEntry::new("some-key".into(), 0.into());
10+
let message_map_1 = Message::map(vec![m]);
11+
12+
let m = (0..5)
13+
.map(|i| MapEntry::new("some-key".into(), i.into()))
14+
.collect::<Vec<MapEntry>>();
15+
16+
let message_map_5 = Message::map(m);
17+
18+
let m = (0..10)
19+
.map(|i| MapEntry::new("some-key".into(), i.into()))
20+
.collect::<Vec<MapEntry>>();
21+
22+
let message_map_10 = Message::map(m);
23+
924
let m = (0..100)
1025
.map(|i| MapEntry::new("some-key".into(), i.into()))
1126
.collect::<Vec<MapEntry>>();
1227

13-
let message_map = Message::map(m);
28+
let message_map_100 = Message::map(m);
1429

1530
let mut buffer = vec![0u8; 4096];
1631

1732
c.bench_function("msgpack nil", |b| {
18-
b.iter(|| message_nil.pack(black_box(&mut buffer)).unwrap())
33+
b.iter(|| {
34+
message_nil
35+
.pack(black_box(&mut buffer.as_mut_slice()))
36+
.unwrap()
37+
})
1938
});
2039

2140
c.bench_function("msgunpack nil", |b| {
@@ -27,7 +46,11 @@ pub fn pack(c: &mut Criterion) {
2746
});
2847

2948
c.bench_function("msgpack int", |b| {
30-
b.iter(|| message_int.pack(black_box(&mut buffer)).unwrap())
49+
b.iter(|| {
50+
message_int
51+
.pack(black_box(&mut buffer.as_mut_slice()))
52+
.unwrap()
53+
})
3154
});
3255

3356
c.bench_function("msgunpack int", |b| {
@@ -38,15 +61,67 @@ pub fn pack(c: &mut Criterion) {
3861
b.iter(|| unsafe { MessageRef::unpack(black_box(&mut buffer.as_slice())).unwrap() })
3962
});
4063

41-
c.bench_function("msgpack map", |b| {
42-
b.iter(|| message_map.pack(black_box(&mut buffer)).unwrap())
64+
c.bench_function("msgpack map 1", |b| {
65+
b.iter(|| {
66+
message_map_1
67+
.pack(black_box(&mut buffer.as_mut_slice()))
68+
.unwrap()
69+
})
70+
});
71+
72+
c.bench_function("msgunpack map 1", |b| {
73+
b.iter(|| Message::unpack(black_box(&mut buffer.as_slice())).unwrap())
74+
});
75+
76+
c.bench_function("msgunpack ref map 1", |b| {
77+
b.iter(|| unsafe { MessageRef::unpack(black_box(&mut buffer.as_slice())).unwrap() })
78+
});
79+
80+
c.bench_function("msgpack map 5", |b| {
81+
b.iter(|| {
82+
message_map_5
83+
.pack(black_box(&mut buffer.as_mut_slice()))
84+
.unwrap()
85+
})
86+
});
87+
88+
c.bench_function("msgunpack map 5", |b| {
89+
b.iter(|| Message::unpack(black_box(&mut buffer.as_slice())).unwrap())
90+
});
91+
92+
c.bench_function("msgunpack ref map 5", |b| {
93+
b.iter(|| unsafe { MessageRef::unpack(black_box(&mut buffer.as_slice())).unwrap() })
94+
});
95+
96+
c.bench_function("msgpack map 10", |b| {
97+
b.iter(|| {
98+
message_map_10
99+
.pack(black_box(&mut buffer.as_mut_slice()))
100+
.unwrap()
101+
})
102+
});
103+
104+
c.bench_function("msgunpack map 10", |b| {
105+
b.iter(|| Message::unpack(black_box(&mut buffer.as_slice())).unwrap())
106+
});
107+
108+
c.bench_function("msgunpack ref map 10", |b| {
109+
b.iter(|| unsafe { MessageRef::unpack(black_box(&mut buffer.as_slice())).unwrap() })
110+
});
111+
112+
c.bench_function("msgpack map 100", |b| {
113+
b.iter(|| {
114+
message_map_100
115+
.pack(black_box(&mut buffer.as_mut_slice()))
116+
.unwrap()
117+
})
43118
});
44119

45-
c.bench_function("msgunpack map", |b| {
120+
c.bench_function("msgunpack map 100", |b| {
46121
b.iter(|| Message::unpack(black_box(&mut buffer.as_slice())).unwrap())
47122
});
48123

49-
c.bench_function("msgunpack ref map", |b| {
124+
c.bench_function("msgunpack ref map 100", |b| {
50125
b.iter(|| unsafe { MessageRef::unpack(black_box(&mut buffer.as_slice())).unwrap() })
51126
});
52127
}

0 commit comments

Comments
 (0)