This commit is contained in:
re0312 2024-04-04 23:20:38 +08:00
parent 359503635e
commit 702586f705

View File

@ -2,12 +2,12 @@ use bevy_app::{App, Update};
use bevy_ecs::prelude::*;
use bevy_tasks::{ComputeTaskPool, TaskPool};
use criterion::Criterion;
use rand::random;
use std::time::{Duration, Instant};
const T: u64 = 200;
fn s_system<const N: usize>() {
let now = Instant::now();
while Instant::now() - now < Duration::from_micros(T) {
while Instant::now() - now < Duration::from_nanos(1) {
// spin, simulating work being done
}
}
@ -30,19 +30,14 @@ pub fn executor(c: &mut Criterion) {
chain_systems!(schedule;0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
schedule.initialize(&mut world);
b.iter_custom(move |iters| {
let iters = iters as u32;
let now = Instant::now();
for _ in 0..iters {
schedule.run(&mut world);
}
// calculate the real overhead of Executor
(now.elapsed() - Duration::from_micros(T * 16)) / iters
b.iter(move || {
schedule.run(&mut world);
});
});
ComputeTaskPool::get_or_init(TaskPool::default);
let thread_num = ComputeTaskPool::get().thread_num();
for system_count_per_batch in [1, 10, 50, 100] {
group.bench_function(
format!(
@ -59,17 +54,8 @@ pub fn executor(c: &mut Criterion) {
}
schedule.initialize(&mut world);
b.iter_custom(move |iters| {
let iters = iters as u32;
let now = Instant::now();
for _ in 0..iters {
schedule.run(&mut world);
}
// calculate the real overhead of Executor
(now.elapsed()
- ((Duration::from_micros(T * 16 * system_count_per_batch))
/ (thread_num as u32).min(system_count_per_batch as u32)))
/ iters
b.iter(move || {
schedule.run(&mut world);
});
},
);