File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ harness = false
23
23
name = " ipc_shared_mem"
24
24
harness = false
25
25
26
+ [[bench ]]
27
+ name = " struct_ipc"
28
+ harness = false
29
+
26
30
[features ]
27
31
default = []
28
32
force-inprocess = []
@@ -52,6 +56,7 @@ crossbeam-utils = "0.8"
52
56
futures-test = " 0.3"
53
57
static_assertions = " 1.1.0"
54
58
criterion = { version = " 0.5" , features = [" html_reports" ] }
59
+ rand = " 0.9.2"
55
60
56
61
[target .'cfg(target_os = "windows")' .dependencies .windows ]
57
62
version = " 0.61"
Original file line number Diff line number Diff line change @@ -70,4 +70,5 @@ criterion_group!(
70
70
transfer_receivers<8 >,
71
71
transfer_receivers<64 >,
72
72
) ;
73
+
73
74
criterion_main ! ( benches) ;
Original file line number Diff line number Diff line change
1
+ use criterion:: { criterion_group, criterion_main, Criterion } ;
2
+ use ipc_channel:: ipc;
3
+ use rand:: prelude:: * ;
4
+ use serde:: { Deserialize , Serialize } ;
5
+
6
+ #[ derive( Clone , Serialize , Deserialize ) ]
7
+ enum Test {
8
+ Msg0 ,
9
+ Msg1 ,
10
+ Msg2 ( u32 , u32 ) ,
11
+ Msg3 ( u32 , u32 , u32 ) ,
12
+ Msg4 ( String ) ,
13
+ Msg5 ,
14
+ Msg6 ,
15
+ }
16
+
17
+ impl Test {
18
+ fn new ( rng : & mut ThreadRng ) -> Self {
19
+ match rng. random_range ( 0 ..=6 ) {
20
+ 0 => Self :: Msg0 ,
21
+ 1 => Self :: Msg1 ,
22
+ 2 => Self :: Msg2 ( 23 , 42 ) ,
23
+ 3 => Self :: Msg3 ( 23 , 42 , 243 ) ,
24
+ 4 => Self :: Msg4 ( String :: from ( "This is a test string of medium size" ) ) ,
25
+ 5 => Self :: Msg5 ,
26
+ 6 => Self :: Msg6 ,
27
+ _ => Self :: Msg6 ,
28
+ }
29
+ }
30
+ }
31
+
32
+ fn transfer_simple_struct ( criterion : & mut Criterion ) {
33
+ criterion. bench_function ( "transfer_simple_struct" , |bencher| {
34
+ let ( tx, rx) = ipc:: channel ( ) . unwrap ( ) ;
35
+ let mut rng = rand:: rng ( ) ;
36
+
37
+ bencher. iter_batched (
38
+ || Test :: new ( & mut rng) ,
39
+ |s| {
40
+ tx. send ( s) . unwrap ( ) ;
41
+ rx. recv ( ) . unwrap ( ) ;
42
+ } ,
43
+ criterion:: BatchSize :: SmallInput ,
44
+ ) ;
45
+ } ) ;
46
+ }
47
+
48
+ criterion_group ! ( benches, transfer_simple_struct, ) ;
49
+
50
+ criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments