Skip to content

Commit 342e4e7

Browse files
authored
Revert "perf(transport): remove Server::timers (#1784)" (#1800)
This reverts commit 61fcd28.
1 parent 6daede0 commit 342e4e7

File tree

5 files changed

+509
-42
lines changed

5 files changed

+509
-42
lines changed

neqo-common/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ features = ["timeapi"]
3434
[lib]
3535
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
3636
bench = false
37+
38+
[[bench]]
39+
name = "timer"
40+
harness = false

neqo-common/benches/timer.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4+
// option. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
use std::time::{Duration, Instant};
8+
9+
use criterion::{criterion_group, criterion_main, Criterion};
10+
use neqo_common::timer::Timer;
11+
use test_fixture::now;
12+
13+
fn benchmark_timer(c: &mut Criterion) {
14+
c.bench_function("drain a timer quickly", |b| {
15+
b.iter_batched_ref(
16+
make_timer,
17+
|(_now, timer)| {
18+
while let Some(t) = timer.next_time() {
19+
assert!(timer.take_next(t).is_some());
20+
}
21+
},
22+
criterion::BatchSize::SmallInput,
23+
);
24+
});
25+
}
26+
27+
fn make_timer() -> (Instant, Timer<()>) {
28+
const TIMES: &[u64] = &[1, 2, 3, 5, 8, 13, 21, 34];
29+
30+
let now = now();
31+
let mut timer = Timer::new(now, Duration::from_millis(777), 100);
32+
for &t in TIMES {
33+
timer.add(now + Duration::from_secs(t), ());
34+
}
35+
(now, timer)
36+
}
37+
38+
criterion_group!(benches, benchmark_timer);
39+
criterion_main!(benches);

neqo-common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod hrtime;
1414
mod incrdecoder;
1515
pub mod log;
1616
pub mod qlog;
17+
pub mod timer;
1718
pub mod tos;
1819

1920
use std::fmt::Write;

0 commit comments

Comments
 (0)