Skip to content

Commit c430e32

Browse files
Add benchmark for timestamped add_sample
1 parent 3f3efef commit c430e32

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

libdd-profiling/benches/add_samples.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,20 @@ pub fn bench_add_sample_vs_add2(c: &mut Criterion) {
106106
let functions = dict.functions();
107107
let thread_id = get_current_thread_id();
108108
let thread_id_key: StringId2 = strings.try_insert("thread id").unwrap().into();
109-
let labels_api = vec![api::Label {
110-
key: "thread id",
111-
str: "",
112-
num: thread_id,
113-
num_unit: "",
114-
}];
109+
let labels_api = vec![
110+
api::Label {
111+
key: "thread id",
112+
str: "",
113+
num: thread_id,
114+
num_unit: "",
115+
},
116+
api::Label {
117+
key: "thread name",
118+
str: "this thread",
119+
num: 0,
120+
num_unit: "",
121+
},
122+
];
115123

116124
let frames2 = frames.map(|f| {
117125
let set_id = functions
@@ -128,6 +136,23 @@ pub fn bench_add_sample_vs_add2(c: &mut Criterion) {
128136
});
129137
let dict = profiling::profiles::collections::Arc::try_new(dict).unwrap();
130138

139+
c.bench_function("profile_add_sample_timestamped_x1000", |b| {
140+
b.iter(|| {
141+
let mut profile = profiling::internal::Profile::try_new(&sample_types, None).unwrap();
142+
let (locations, values) = make_stack_api(frames.as_slice());
143+
for i in 0..1000 {
144+
let sample = api::Sample {
145+
locations: locations.clone(),
146+
values: &values,
147+
labels: labels_api.clone(),
148+
};
149+
let ts = std::num::NonZeroI64::new(i + 1);
150+
black_box(profile.try_add_sample(sample, ts)).unwrap();
151+
}
152+
black_box(profile.only_for_testing_num_aggregated_samples())
153+
})
154+
});
155+
131156
c.bench_function("profile_add_sample_frames_x1000", |b| {
132157
b.iter(|| {
133158
let mut profile = profiling::internal::Profile::try_new(&sample_types, None).unwrap();

0 commit comments

Comments
 (0)