Skip to content

Commit

Permalink
Create sleeper once
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Sep 21, 2023
1 parent 674ebbf commit f7fa221
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions benches/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy::{app::MainScheduleOrder, ecs::schedule::ExecutorKind, prelude::*};
use bevy_replicon::prelude::*;
use criterion::{criterion_group, criterion_main, Criterion};
use serde::{Deserialize, Serialize};
use spin_sleep::{SpinSleeper, SpinStrategy};

#[derive(Component, Clone, Copy, Serialize, Deserialize)]
struct DummyComponent(usize);
Expand All @@ -15,11 +16,12 @@ const ENTITIES: u32 = 900;
const SOCKET_WAIT: Duration = Duration::from_millis(5); // Sometimes it takes time for socket to receive all data.

fn replication(c: &mut Criterion) {
// Use spinner to keep CPU hot in the schedule for stable benchmark results.
let sleeper = SpinSleeper::new(1_000_000_000).with_spin_strategy(SpinStrategy::SpinLoopHint);

c.bench_function("entities send", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
let sleeper = spin_sleep::SpinSleeper::new(1_000_000_000)
.with_spin_strategy(spin_sleep::SpinStrategy::SpinLoopHint);
for _ in 0..iter {
let mut server_app = App::new();
let mut client_app = App::new();
Expand Down Expand Up @@ -48,8 +50,6 @@ fn replication(c: &mut Criterion) {
c.bench_function("entities receive", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
let sleeper = spin_sleep::SpinSleeper::new(1_000_000_000)
.with_spin_strategy(spin_sleep::SpinStrategy::SpinLoopHint);
for _ in 0..iter {
let mut server_app = App::new();
let mut client_app = App::new();
Expand Down Expand Up @@ -78,8 +78,6 @@ fn replication(c: &mut Criterion) {
c.bench_function("entities update send", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
let sleeper = spin_sleep::SpinSleeper::new(1_000_000_000)
.with_spin_strategy(spin_sleep::SpinStrategy::SpinLoopHint);
let mut server_app = App::new();
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
Expand Down Expand Up @@ -119,8 +117,6 @@ fn replication(c: &mut Criterion) {
c.bench_function("entities update receive", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
let sleeper = spin_sleep::SpinSleeper::new(1_000_000_000)
.with_spin_strategy(spin_sleep::SpinStrategy::SpinLoopHint);
let mut server_app = App::new();
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
Expand Down

0 comments on commit f7fa221

Please sign in to comment.