forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.rs
50 lines (40 loc) · 1.33 KB
/
template.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
use criterion::{criterion_group, BatchSize, Criterion};
use chrono::Utc;
use std::convert::TryFrom;
use vector::{config::log_schema, event::Event};
fn bench_elasticsearch_index(c: &mut Criterion) {
use vector::template::Template;
let mut group = c.benchmark_group("template");
group.bench_function("dynamic", |b| {
let index = Template::try_from("index-%Y.%m.%d").unwrap();
let mut event = Event::from("hello world");
event
.as_mut_log()
.insert(log_schema().timestamp_key(), Utc::now());
b.iter_batched(
|| event.clone(),
|event| index.render(&event),
BatchSize::SmallInput,
)
});
group.bench_function("static", |b| {
let index = Template::try_from("index").unwrap();
let mut event = Event::from("hello world");
event
.as_mut_log()
.insert(log_schema().timestamp_key(), Utc::now());
b.iter_batched(
|| event.clone(),
|event| index.render(&event),
BatchSize::SmallInput,
)
});
group.finish();
}
criterion_group!(
name = benches;
// encapsulates CI noise we saw in
// https://github.com/timberio/vector/issues/5394
config = Criterion::default().noise_threshold(0.20);
targets = bench_elasticsearch_index
);