forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.rs
98 lines (90 loc) · 3.25 KB
/
event.rs
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
use bytes::Bytes;
use criterion::{criterion_group, BatchSize, Criterion};
use vector::event::LogEvent;
use vrl::event_path;
fn benchmark_event_iterate(c: &mut Criterion) {
let mut group = c.benchmark_group("event/iterate");
group.bench_function("single-level", |b| {
b.iter_batched_ref(
|| {
let mut log = LogEvent::default();
log.insert(event_path!("key1"), Bytes::from("value1"));
log.insert(event_path!("key2"), Bytes::from("value2"));
log.insert(event_path!("key3"), Bytes::from("value3"));
log
},
|e| e.all_event_fields().unwrap().count(),
BatchSize::SmallInput,
)
});
group.bench_function("nested-keys", |b| {
b.iter_batched_ref(
|| {
let mut log = LogEvent::default();
log.insert(
event_path!("key1", "nested1", "nested2"),
Bytes::from("value1"),
);
log.insert(
event_path!("key1", "nested1", "nested3"),
Bytes::from("value4"),
);
log.insert(event_path!("key3"), Bytes::from("value3"));
log
},
|e| e.all_event_fields().unwrap().count(),
BatchSize::SmallInput,
)
});
group.bench_function("array", |b| {
b.iter_batched_ref(
|| {
let mut log = LogEvent::default();
log.insert(event_path!("key1", "nested1", 0), Bytes::from("value1"));
log.insert(event_path!("key1", "nested1", 1), Bytes::from("value2"));
log
},
|e| e.all_event_fields().unwrap().count(),
BatchSize::SmallInput,
)
});
}
fn benchmark_event_create(c: &mut Criterion) {
let mut group = c.benchmark_group("event/create");
group.bench_function("single-level", |b| {
b.iter(|| {
let mut log = LogEvent::default();
log.insert(event_path!("key1"), Bytes::from("value1"));
log.insert(event_path!("key2"), Bytes::from("value2"));
log.insert(event_path!("key3"), Bytes::from("value3"));
})
});
group.bench_function("nested-keys", |b| {
b.iter(|| {
let mut log = LogEvent::default();
log.insert(
event_path!("key1", "nested1", "nested2"),
Bytes::from("value1"),
);
log.insert(
event_path!("key1", "nested1", "nested3"),
Bytes::from("value4"),
);
log.insert(event_path!("key3"), Bytes::from("value3"));
})
});
group.bench_function("array", |b| {
b.iter(|| {
let mut log = LogEvent::default();
log.insert(event_path!("key1", "nested1", 0), Bytes::from("value1"));
log.insert(event_path!("key1", "nested1", 1), Bytes::from("value2"));
})
});
}
criterion_group!(
name = benches;
// encapsulates inherent CI noise we saw in
// https://github.com/vectordotdev/vector/issues/5394
config = Criterion::default().noise_threshold(0.05);
targets = benchmark_event_create, benchmark_event_iterate
);