1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#![allow(unused_imports)]
use {
fidl::{
encoding::{Context, Decode, Decoder, Encoder, with_tls_encode_buf, WireFormatVersion},
handle::Handle, handle::HandleDisposition, handle::HandleInfo, handle::HandleOp,
ObjectType, Rights,
},
fidl_test_benchmarkfidlresult as test_benchmarkfidlresult,
fuchsia_async as fasync,
fuchsia_criterion::criterion::{BatchSize, Bencher, black_box},
futures::{future, stream::StreamExt},
fuchsia_zircon as zx,
gidl_util::{HandleDef, HandleSubtype, copy_handle, create_handles, select_handle_infos},
std::mem::ManuallyDrop
};
pub const BENCHMARKS: [(&'static str, fn(&mut Bencher)); 6] = [
("Builder/ErrorSyntaxResult_Success", benchmark_error_syntax_result_success_builder),
("Encode/ErrorSyntaxResult_Success", benchmark_error_syntax_result_success_encode),
("Decode/ErrorSyntaxResult_Success", benchmark_error_syntax_result_success_decode),
("Builder/ErrorSyntaxResult_Failure", benchmark_error_syntax_result_failure_builder),
("Encode/ErrorSyntaxResult_Failure", benchmark_error_syntax_result_failure_encode),
("Decode/ErrorSyntaxResult_Failure", benchmark_error_syntax_result_failure_decode),
];
const _V2_CONTEXT: Context = Context { wire_format_version: WireFormatVersion::V2 };
fn benchmark_error_syntax_result_success_builder(b: &mut Bencher) {
b.iter(
|| {
black_box(test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Response(test_benchmarkfidlresult::ErrorSyntaxResponse { ptrs: 1i64, payload_buffer_id: 2u32, payload_offset: 3u64, payload_size: 4u64, flags: 5u32, buffer_config: 6u64, stream_segment_id: 7u64 }) });
},
);
}
fn benchmark_error_syntax_result_success_encode(b: &mut Bencher) {
b.iter_batched_ref(
|| {
test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Response(test_benchmarkfidlresult::ErrorSyntaxResponse { ptrs: 1i64, payload_buffer_id: 2u32, payload_offset: 3u64, payload_size: 4u64, flags: 5u32, buffer_config: 6u64, stream_segment_id: 7u64 }) }
},
|value| {
with_tls_encode_buf(|bytes, handles| {
Encoder::encode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, bytes, handles, &*value).unwrap();
})
},
BatchSize::SmallInput,
);
}
fn benchmark_error_syntax_result_success_decode(b: &mut Bencher) {
b.iter_batched_ref(
|| {
let mut bytes = Vec::<u8>::new();
let mut handles = Vec::<HandleDisposition<'static>>::new();
let original_value = &test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Response(test_benchmarkfidlresult::ErrorSyntaxResponse { ptrs: 1i64, payload_buffer_id: 2u32, payload_offset: 3u64, payload_size: 4u64, flags: 5u32, buffer_config: 6u64, stream_segment_id: 7u64 }) };
Encoder::encode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, &mut bytes, &mut handles, original_value).unwrap();
let handle_infos = fidl::encoding::convert_handle_dispositions_to_infos(handles).unwrap();
(bytes, handle_infos, ManuallyDrop::new(fidl::new_empty!(test_benchmarkfidlresult::ErrorSyntaxResultStruct)))
},
|(bytes, handle_infos, manually_drop_value)| {
let value : &mut test_benchmarkfidlresult::ErrorSyntaxResultStruct = unsafe { std::mem::transmute(manually_drop_value as *mut _) };
Decoder::decode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, bytes, handle_infos, value).unwrap();
unsafe { ManuallyDrop::drop(manually_drop_value) };
},
BatchSize::SmallInput,
);
}
fn benchmark_error_syntax_result_failure_builder(b: &mut Bencher) {
b.iter(
|| {
black_box(test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Err(10u32) });
},
);
}
fn benchmark_error_syntax_result_failure_encode(b: &mut Bencher) {
b.iter_batched_ref(
|| {
test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Err(10u32) }
},
|value| {
with_tls_encode_buf(|bytes, handles| {
Encoder::encode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, bytes, handles, &*value).unwrap();
})
},
BatchSize::SmallInput,
);
}
fn benchmark_error_syntax_result_failure_decode(b: &mut Bencher) {
b.iter_batched_ref(
|| {
let mut bytes = Vec::<u8>::new();
let mut handles = Vec::<HandleDisposition<'static>>::new();
let original_value = &test_benchmarkfidlresult::ErrorSyntaxResultStruct { result: test_benchmarkfidlresult::ErrorSyntaxResult::Err(10u32) };
Encoder::encode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, &mut bytes, &mut handles, original_value).unwrap();
let handle_infos = fidl::encoding::convert_handle_dispositions_to_infos(handles).unwrap();
(bytes, handle_infos, ManuallyDrop::new(fidl::new_empty!(test_benchmarkfidlresult::ErrorSyntaxResultStruct)))
},
|(bytes, handle_infos, manually_drop_value)| {
let value : &mut test_benchmarkfidlresult::ErrorSyntaxResultStruct = unsafe { std::mem::transmute(manually_drop_value as *mut _) };
Decoder::decode_with_context::<test_benchmarkfidlresult::ErrorSyntaxResultStruct>(_V2_CONTEXT, bytes, handle_infos, value).unwrap();
unsafe { ManuallyDrop::drop(manually_drop_value) };
},
BatchSize::SmallInput,
);
}