Skip to content

Commit

Permalink
Revert "perf(transport): remove Server::timers (mozilla#1784)"
Browse files Browse the repository at this point in the history
This reverts commit 61fcd28.
  • Loading branch information
KershawChang committed Apr 8, 2024
1 parent aca1352 commit e93d2ed
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 42 deletions.
4 changes: 4 additions & 0 deletions neqo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ features = ["timeapi"]
[lib]
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false

[[bench]]
name = "timer"
harness = false
39 changes: 39 additions & 0 deletions neqo-common/benches/timer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::time::{Duration, Instant};

use criterion::{criterion_group, criterion_main, Criterion};
use neqo_common::timer::Timer;
use test_fixture::now;

fn benchmark_timer(c: &mut Criterion) {
c.bench_function("drain a timer quickly", |b| {
b.iter_batched_ref(
make_timer,
|(_now, timer)| {
while let Some(t) = timer.next_time() {
assert!(timer.take_next(t).is_some());
}
},
criterion::BatchSize::SmallInput,
);
});
}

fn make_timer() -> (Instant, Timer<()>) {
const TIMES: &[u64] = &[1, 2, 3, 5, 8, 13, 21, 34];

let now = now();
let mut timer = Timer::new(now, Duration::from_millis(777), 100);
for &t in TIMES {
timer.add(now + Duration::from_secs(t), ());
}
(now, timer)
}

criterion_group!(benches, benchmark_timer);
criterion_main!(benches);
1 change: 1 addition & 0 deletions neqo-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod hrtime;
mod incrdecoder;
pub mod log;
pub mod qlog;
pub mod timer;
pub mod tos;

use std::fmt::Write;
Expand Down
Loading

0 comments on commit e93d2ed

Please sign in to comment.