Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions benches/benches/bevy_ecs/fragmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn iter_frag_empty(c: &mut Criterion) {
res += e.to_bits();
black_box(t);
});
black_box(res);
});
});
group.bench_function("foreach_sparse", |b| {
Expand All @@ -46,6 +47,7 @@ fn iter_frag_empty(c: &mut Criterion) {
res += e.to_bits();
black_box(t);
});
black_box(res);
});
});
group.finish();
Expand Down
32 changes: 19 additions & 13 deletions benches/benches/bevy_ecs/world/entity_hash.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy_ecs::entity::{Entity, EntityGeneration, EntityHashSet};
use chacha20::ChaCha8Rng;
use core::hint::black_box;
use criterion::{BenchmarkId, Criterion, Throughput};
use rand::{RngExt, SeedableRng};

Expand Down Expand Up @@ -42,19 +43,22 @@ pub fn entity_set_build_and_lookup(c: &mut Criterion) {
});
group.bench_function(BenchmarkId::new("entity_set_lookup_hit", size), |bencher| {
let set = EntityHashSet::from_iter(entities.iter().copied());
bencher.iter(|| entities.iter().copied().filter(|e| set.contains(e)).count());
bencher
.iter(|| black_box(entities.iter().copied().filter(|e| set.contains(e)).count()));
});
group.bench_function(
BenchmarkId::new("entity_set_lookup_miss_id", size),
|bencher| {
let set = EntityHashSet::from_iter(entities.iter().copied());
bencher.iter(|| {
entities
.iter()
.copied()
.map(|e| Entity::from_bits(e.to_bits() + 1))
.filter(|e| set.contains(e))
.count()
black_box(
entities
.iter()
.copied()
.map(|e| Entity::from_bits(e.to_bits() + 1))
.filter(|e| set.contains(e))
.count(),
)
});
},
);
Expand All @@ -63,12 +67,14 @@ pub fn entity_set_build_and_lookup(c: &mut Criterion) {
|bencher| {
let set = EntityHashSet::from_iter(entities.iter().copied());
bencher.iter(|| {
entities
.iter()
.copied()
.map(|e| Entity::from_bits(e.to_bits() + (1 << 32)))
.filter(|e| set.contains(e))
.count()
black_box(
entities
.iter()
.copied()
.map(|e| Entity::from_bits(e.to_bits() + (1 << 32)))
.filter(|e| set.contains(e))
.count(),
)
});
},
);
Expand Down
14 changes: 7 additions & 7 deletions benches/benches/bevy_reflect/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ fn add(a: i32, b: i32) -> i32 {
fn typed(c: &mut Criterion) {
c.benchmark_group(bench!("typed"))
.bench_function("function", |b| {
b.iter(|| add.get_function_info());
b.iter(|| black_box(add.get_function_info()));
})
.bench_function("closure", |b| {
let capture = 25;
let closure = |a: i32| a + capture;
b.iter(|| closure.get_function_info());
b.iter(|| black_box(closure.get_function_info()));
})
.bench_function("closure_mut", |b| {
let mut capture = 25;
let closure = |a: i32| capture += a;
b.iter(|| closure.get_function_info());
b.iter(|| black_box(closure.get_function_info()));
});
}

fn into(c: &mut Criterion) {
c.benchmark_group(bench!("into"))
.bench_function("function", |b| {
b.iter(|| add.into_function());
b.iter(|| black_box(add.into_function()));
})
.bench_function("closure", |b| {
let capture = 25;
let closure = |a: i32| a + capture;
b.iter(|| closure.into_function());
b.iter(|| black_box(closure.into_function()));
})
.bench_function("closure_mut", |b| {
let mut _capture = 25;
Expand All @@ -53,7 +53,7 @@ fn into(c: &mut Criterion) {
reason = "rustc bug https://github.com/rust-lang/rust/issues/149889"
)]
let closure = move |a: i32| _capture += a;
b.iter(|| closure.into_function_mut());
b.iter(|| black_box(closure.into_function_mut()));
});
}

Expand Down Expand Up @@ -98,7 +98,7 @@ fn clone(c: &mut Criterion) {
c.benchmark_group(bench!("clone"))
.bench_function("function", |b| {
let add = add.into_function();
b.iter(|| add.clone());
b.iter(|| black_box(add.clone()));
});
}

Expand Down
12 changes: 6 additions & 6 deletions benches/benches/bevy_reflect/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ fn concrete_struct_type_info(criterion: &mut Criterion) {
BenchmarkId::new("NonGeneric", field_count),
&standard,
|bencher, s| {
bencher.iter(|| s.get_represented_type_info());
bencher.iter(|| black_box(s.get_represented_type_info()));
},
);
group.bench_with_input(
BenchmarkId::new("Generic", field_count),
&generic,
|bencher, s| {
bencher.iter(|| s.get_represented_type_info());
bencher.iter(|| black_box(s.get_represented_type_info()));
},
);
}
Expand Down Expand Up @@ -206,14 +206,14 @@ fn concrete_struct_to_dynamic_struct(criterion: &mut Criterion) {
BenchmarkId::new("NonGeneric", field_count),
&standard,
|bencher, s| {
bencher.iter(|| s.to_dynamic_struct());
bencher.iter(|| black_box(s.to_dynamic_struct()));
},
);
group.bench_with_input(
BenchmarkId::new("Generic", field_count),
&generic,
|bencher, s| {
bencher.iter(|| s.to_dynamic_struct());
bencher.iter(|| black_box(s.to_dynamic_struct()));
},
);
}
Expand All @@ -237,7 +237,7 @@ fn dynamic_struct_to_dynamic_struct(criterion: &mut Criterion) {
BenchmarkId::from_parameter(field_count),
&s,
|bencher, s| {
bencher.iter(|| s.to_dynamic_struct());
bencher.iter(|| black_box(s.to_dynamic_struct()));
},
);
}
Expand Down Expand Up @@ -347,7 +347,7 @@ fn dynamic_struct_get_field(criterion: &mut Criterion) {
}

let field = black_box("field_63");
bencher.iter(|| s.get_field::<()>(field));
bencher.iter(|| black_box(s.get_field::<()>(field)));
},
);
}
Expand Down