Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Sep 6, 2023
1 parent 1af4ddd commit 8ef6d3f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Derive `Clone, Copy` for `Replication`.
- Derive `Clone` and `Copy` for `Replication`.
- Make `ServerPlugin` fields private and add `ServerPlugin::new`.
- Make `AckedTicks` public.
- Make `NetworkEntityMap` public.
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ derive_more = { version = "0.99", default-features = false, features = [

[dev-dependencies]
serde_test = "1.0"
criterion = { version = "0.5", default-features = false, features = [
"cargo_bench_support",
] }
anyhow = "1.0"
clap = { version = "4.1", features = ["derive"] }
bevy = { version = "0.11", default-features = false, features = [
Expand All @@ -42,3 +45,7 @@ bevy = { version = "0.11", default-features = false, features = [
"x11",
"default_font",
] }

[[bench]]
name = "replication"
harness = false
85 changes: 85 additions & 0 deletions benches/replication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#[path = "../tests/common/mod.rs"]
mod common;

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

use bevy::prelude::*;
use bevy_replicon::prelude::*;
use criterion::{criterion_group, criterion_main, Criterion};

#[derive(Component, Reflect, Default, Clone, Copy)]
#[reflect(Component)]
struct DummyComponent;

const ENTITIES: u32 = 900;

fn replication(c: &mut Criterion) {
c.bench_function("entities send", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
for _ in 0..iter {
let mut server_app = App::new();
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
app.add_plugins((
MinimalPlugins,
ReplicationPlugins.set(ServerPlugin::new(TickPolicy::Manual)),
))
.replicate::<DummyComponent>();
}
common::setup(&mut server_app, &mut client_app);

server_app
.world
.spawn_batch([(Replication, DummyComponent); ENTITIES as usize]);

let instant = Instant::now();
server_app.update();
elapsed += instant.elapsed();

client_app.update();
assert_eq!(client_app.world.entities().len(), ENTITIES);
}

elapsed
})
});

c.bench_function("entities receive", |b| {
b.iter_custom(|iter| {
let mut elapsed = Duration::ZERO;
for _ in 0..iter {
let mut server_app = App::new();
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
app.add_plugins((
MinimalPlugins,
ReplicationPlugins.set(ServerPlugin::new(TickPolicy::Manual)),
))
.replicate::<DummyComponent>();
}
common::setup(&mut server_app, &mut client_app);

server_app
.world
.spawn_batch([(Replication, DummyComponent); ENTITIES as usize]);

server_app.update();

let instant = Instant::now();
client_app.update();
elapsed += instant.elapsed();
assert_eq!(client_app.world.entities().len(), ENTITIES);
}

elapsed
})
});
}

criterion_group! {
name = benches;
config = Criterion::default().sample_size(50);
targets = replication
}
criterion_main!(benches);

0 comments on commit 8ef6d3f

Please sign in to comment.