Fix clippy issue for benches crate (#6806)

# Objective

- https://github.com/bevyengine/bevy/pull/3505 marked `S-Adopt-Me` , this pr is to continue his work.

## Solution

- run `cargo clippy --workspace --all-targets --all-features -- -Aclippy::type_complexity -Wclippy::doc_markdown -Wclippy::redundant_else -Wclippy::match_same_arms -Wclippy::semicolon_if_nothing_returned -Wclippy::explicit_iter_loop -Wclippy::map_flatten -Dwarnings` under benches dir.
- fix issue according to suggestion.
This commit is contained in:
张林伟 2023-01-11 09:32:07 +00:00
parent 512f376fc1
commit bb79903938
8 changed files with 24 additions and 29 deletions

View file

@ -109,7 +109,7 @@ pub fn added_archetypes(criterion: &mut Criterion) {
stage.run(&mut world);
},
criterion::BatchSize::LargeInput,
)
);
},
);
}

View file

@ -110,11 +110,11 @@ pub fn build_schedule(criterion: &mut Criterion) {
// Not particularly realistic but this can be refined later.
for i in 0..graph_size {
let mut sys = empty_system.label(labels[i]).before(DummyLabel);
for a in 0..i {
sys = sys.after(labels[a]);
for label in labels.iter().take(i) {
sys = sys.after(*label);
}
for b in i + 1..graph_size {
sys = sys.before(labels[b]);
for label in &labels[i + 1..graph_size] {
sys = sys.before(*label);
}
app.add_system(sys);
}

View file

@ -58,7 +58,7 @@ pub fn empty_systems(criterion: &mut Criterion) {
});
});
}
group.finish()
group.finish();
}
pub fn busy_systems(criterion: &mut Criterion) {
@ -107,7 +107,7 @@ pub fn busy_systems(criterion: &mut Criterion) {
);
}
}
group.finish()
group.finish();
}
pub fn contrived(criterion: &mut Criterion) {
@ -158,5 +158,5 @@ pub fn contrived(criterion: &mut Criterion) {
);
}
}
group.finish()
group.finish();
}

View file

@ -61,7 +61,6 @@ pub fn spawn_commands(criterion: &mut Criterion) {
entity.despawn();
}
}
drop(commands);
command_queue.apply(&mut world);
});
});
@ -82,7 +81,7 @@ pub fn insert_commands(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(4));
let entity_count = 10_000;
group.bench_function(format!("insert"), |bencher| {
group.bench_function("insert", |bencher| {
let mut world = World::default();
let mut command_queue = CommandQueue::default();
let mut entities = Vec::new();
@ -97,11 +96,10 @@ pub fn insert_commands(criterion: &mut Criterion) {
.entity(*entity)
.insert((Matrix::default(), Vec3::default()));
}
drop(commands);
command_queue.apply(&mut world);
});
});
group.bench_function(format!("insert_batch"), |bencher| {
group.bench_function("insert_batch", |bencher| {
let mut world = World::default();
let mut command_queue = CommandQueue::default();
let mut entities = Vec::new();
@ -116,7 +114,6 @@ pub fn insert_commands(criterion: &mut Criterion) {
values.push((*entity, (Matrix::default(), Vec3::default())));
}
commands.insert_or_spawn_batch(values);
drop(commands);
command_queue.apply(&mut world);
});
});
@ -160,7 +157,6 @@ pub fn fake_commands(criterion: &mut Criterion) {
commands.add(FakeCommandB(0));
}
}
drop(commands);
command_queue.apply(&mut world);
});
});
@ -203,7 +199,6 @@ pub fn sized_commands_impl<T: Default + Command>(criterion: &mut Criterion) {
for _ in 0..command_count {
commands.add(T::default());
}
drop(commands);
command_queue.apply(&mut world);
});
});

View file

@ -273,7 +273,7 @@ pub fn query_get_component_simple(criterion: &mut Criterion) {
bencher.iter(|| {
for _x in 0..100000 {
let mut a = unsafe { query.get_unchecked(&mut world, entity).unwrap() };
let mut a = unsafe { query.get_unchecked(&world, entity).unwrap() };
a.0 += 1.0;
}
});

View file

@ -44,7 +44,7 @@ fn list_apply<M, LBase, LPatch, F1, F2, F3>(
let f_base = f_base(size);
let patch = f_patch(size);
bencher.iter_batched(
|| f_base(),
f_base,
|mut base| base.apply(black_box(&patch)),
BatchSize::SmallInput,
);
@ -58,7 +58,7 @@ fn concrete_list_apply(criterion: &mut Criterion) {
group.warm_up_time(WARM_UP_TIME);
group.measurement_time(MEASUREMENT_TIME);
let empty_base = |_: usize| || Vec::<u64>::new();
let empty_base = |_: usize| Vec::<u64>::new;
let full_base = |size: usize| move || iter::repeat(0).take(size).collect::<Vec<u64>>();
let patch = |size: usize| iter::repeat(1).take(size).collect::<Vec<u64>>();

View file

@ -60,7 +60,7 @@ fn concrete_map_apply(criterion: &mut Criterion) {
group.warm_up_time(WARM_UP_TIME);
group.measurement_time(MEASUREMENT_TIME);
let empty_base = |_: usize| || HashMap::<u64, u64>::default();
let empty_base = |_: usize| HashMap::<u64, u64>::default;
let key_range_base = |size: usize| {
move || {
@ -136,7 +136,7 @@ fn dynamic_map_apply(criterion: &mut Criterion) {
group.warm_up_time(WARM_UP_TIME);
group.measurement_time(MEASUREMENT_TIME);
let empty_base = |_: usize| || DynamicMap::default();
let empty_base = |_: usize| DynamicMap::default;
let key_range_base = |size: usize| {
move || {
@ -240,8 +240,8 @@ fn dynamic_map_get(criterion: &mut Criterion) {
}
bencher.iter(|| {
for i in 0..size {
let key = black_box(&keys[i]);
for key in keys.iter().take(size) {
let key = black_box(key);
assert!(map.get(key).is_some());
}
});
@ -262,7 +262,7 @@ fn dynamic_map_insert(criterion: &mut Criterion) {
&size,
|bencher, &size| {
bencher.iter_batched(
|| DynamicMap::default(),
DynamicMap::default,
|mut map| {
for i in 0..size as u64 {
let key = black_box(i);

View file

@ -28,7 +28,7 @@ fn bench_overhead(c: &mut Criterion) {
c.bench_function("overhead_iter", |b| {
b.iter(|| {
v.iter_mut().for_each(noop);
})
});
});
let mut v = (0..10000).collect::<Vec<usize>>();
@ -41,7 +41,7 @@ fn bench_overhead(c: &mut Criterion) {
|b, _| {
b.iter(|| {
ParChunksMut(v.chunks_mut(100)).for_each(&pool, noop);
})
});
},
);
}
@ -63,7 +63,7 @@ fn bench_for_each(c: &mut Criterion) {
busy_work(10000);
*x *= *x;
});
})
});
});
let mut v = (0..10000).collect::<Vec<usize>>();
@ -79,7 +79,7 @@ fn bench_for_each(c: &mut Criterion) {
busy_work(10000);
*x *= *x;
});
})
});
},
);
}
@ -109,7 +109,7 @@ fn bench_many_maps(c: &mut Criterion) {
.map(|x| busy_doubles(x, 1000))
.map(|x| busy_doubles(x, 1000))
.for_each(drop);
})
});
});
let v = (0..10000).collect::<Vec<usize>>();
@ -133,7 +133,7 @@ fn bench_many_maps(c: &mut Criterion) {
.map(|x| busy_doubles(x, 1000))
.map(|x| busy_doubles(x, 1000))
.for_each(&pool, drop);
})
});
},
);
}