Skip to content

Commit

Permalink
Add constant and remove two possible extra sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Sep 20, 2023
1 parent 0b7d540 commit 55782fd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions benches/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
struct DummyComponent(usize);

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) {
c.bench_function("entities send", |b| {
Expand All @@ -33,7 +34,7 @@ fn replication(c: &mut Criterion) {
server_app.update();
elapsed += instant.elapsed();

std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);
client_app.update();
assert_eq!(client_app.world.entities().len(), ENTITIES);
}
Expand All @@ -58,7 +59,7 @@ fn replication(c: &mut Criterion) {
.spawn_batch([(Replication, DummyComponent(0)); ENTITIES as usize]);

server_app.update();
std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);

let instant = Instant::now();
client_app.update();
Expand Down Expand Up @@ -86,7 +87,7 @@ fn replication(c: &mut Criterion) {
let mut query = server_app.world.query::<&mut DummyComponent>();

server_app.update();
std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);
client_app.update();
assert_eq!(client_app.world.entities().len(), ENTITIES);

Expand All @@ -95,12 +96,11 @@ fn replication(c: &mut Criterion) {
dummy_component.0 += 1;
}

std::thread::sleep(Duration::from_millis(5));
let instant = Instant::now();
server_app.update();
elapsed += instant.elapsed();

std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);
client_app.update();
assert_eq!(client_app.world.entities().len(), ENTITIES);
}
Expand All @@ -125,7 +125,7 @@ fn replication(c: &mut Criterion) {
let mut query = server_app.world.query::<&mut DummyComponent>();

server_app.update();
std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);
client_app.update();
assert_eq!(client_app.world.entities().len(), ENTITIES);

Expand All @@ -134,9 +134,8 @@ fn replication(c: &mut Criterion) {
dummy_component.0 += 1;
}

std::thread::sleep(Duration::from_millis(5));
server_app.update();
std::thread::sleep(Duration::from_millis(5));
std::thread::sleep(SOCKET_WAIT);

let instant = Instant::now();
client_app.update();
Expand Down

0 comments on commit 55782fd

Please sign in to comment.