|
| 1 | +use criterion::*; |
| 2 | +use ecs_bench_suite::*; |
| 3 | + |
| 4 | +fn bench_simple_insert(c: &mut Criterion) { |
| 5 | + let mut group = c.benchmark_group("simple_insert"); |
| 6 | + group.bench_function("legion", |b| { |
| 7 | + let mut bench = legion::simple_insert::Benchmark::new(); |
| 8 | + b.iter(move || bench.run()); |
| 9 | + }); |
| 10 | + group.bench_function("legion_0.2.4", |b| { |
| 11 | + let mut bench = legion_2_4::simple_insert::Benchmark::new(); |
| 12 | + b.iter(move || bench.run()); |
| 13 | + }); |
| 14 | + group.bench_function("bevy", |b| { |
| 15 | + let mut bench = bevy::simple_insert::Benchmark::new(); |
| 16 | + b.iter(move || bench.run()); |
| 17 | + }); |
| 18 | + group.bench_function("shipyard", |b| { |
| 19 | + let mut bench = shipyard::simple_insert::Benchmark::new(); |
| 20 | + b.iter(move || bench.run()); |
| 21 | + }); |
| 22 | +} |
| 23 | + |
| 24 | +fn bench_simple_iter(c: &mut Criterion) { |
| 25 | + let mut group = c.benchmark_group("simple_iter"); |
| 26 | + group.bench_function("legion", |b| { |
| 27 | + let mut bench = legion::simple_iter::Benchmark::new(); |
| 28 | + b.iter(move || bench.run()); |
| 29 | + }); |
| 30 | + group.bench_function("legion_0.2.4", |b| { |
| 31 | + let mut bench = legion_2_4::simple_iter::Benchmark::new(); |
| 32 | + b.iter(move || bench.run()); |
| 33 | + }); |
| 34 | + group.bench_function("bevy", |b| { |
| 35 | + let mut bench = bevy::simple_iter::Benchmark::new(); |
| 36 | + b.iter(move || bench.run()); |
| 37 | + }); |
| 38 | + group.bench_function("shipyard", |b| { |
| 39 | + let mut bench = shipyard::simple_iter::Benchmark::new(); |
| 40 | + b.iter(move || bench.run()); |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +fn bench_frag_iter_bc(c: &mut Criterion) { |
| 45 | + let mut group = c.benchmark_group("fragmented_iter"); |
| 46 | + group.bench_function("legion", |b| { |
| 47 | + let mut bench = legion::frag_iter::Benchmark::new(); |
| 48 | + b.iter(move || bench.run()); |
| 49 | + }); |
| 50 | + group.bench_function("legion_0.2.4", |b| { |
| 51 | + let mut bench = legion_2_4::frag_iter::Benchmark::new(); |
| 52 | + b.iter(move || bench.run()); |
| 53 | + }); |
| 54 | + group.bench_function("bevy", |b| { |
| 55 | + let mut bench = bevy::frag_iter::Benchmark::new(); |
| 56 | + b.iter(move || bench.run()); |
| 57 | + }); |
| 58 | + group.bench_function("shipyard", |b| { |
| 59 | + let mut bench = shipyard::frag_iter::Benchmark::new(); |
| 60 | + b.iter(move || bench.run()); |
| 61 | + }); |
| 62 | +} |
| 63 | + |
| 64 | +fn bench_schedule(c: &mut Criterion) { |
| 65 | + let mut group = c.benchmark_group("schedule"); |
| 66 | + group.bench_function("legion", |b| { |
| 67 | + let mut bench = legion::schedule::Benchmark::new(); |
| 68 | + b.iter(move || bench.run()); |
| 69 | + }); |
| 70 | + group.bench_function("legion_0.2.4", |b| { |
| 71 | + let mut bench = legion_2_4::schedule::Benchmark::new(); |
| 72 | + b.iter(move || bench.run()); |
| 73 | + }); |
| 74 | + group.bench_function("bevy", |b| { |
| 75 | + let mut bench = bevy::schedule::Benchmark::new(); |
| 76 | + b.iter(move || bench.run()); |
| 77 | + }); |
| 78 | + group.bench_function("shipyard", |b| { |
| 79 | + let mut bench = shipyard::schedule::Benchmark::new(); |
| 80 | + b.iter(move || bench.run()); |
| 81 | + }); |
| 82 | +} |
| 83 | + |
| 84 | +fn bench_heavy_compute(c: &mut Criterion) { |
| 85 | + let mut group = c.benchmark_group("heavy_compute"); |
| 86 | + group.bench_function("legion", |b| { |
| 87 | + let mut bench = legion::heavy_compute::Benchmark::new(); |
| 88 | + b.iter(move || bench.run()); |
| 89 | + }); |
| 90 | + group.bench_function("legion_0.2.4", |b| { |
| 91 | + let mut bench = legion_2_4::heavy_compute::Benchmark::new(); |
| 92 | + b.iter(move || bench.run()); |
| 93 | + }); |
| 94 | + group.bench_function("bevy", |b| { |
| 95 | + let mut bench = bevy::heavy_compute::Benchmark::new(); |
| 96 | + b.iter(move || bench.run()); |
| 97 | + }); |
| 98 | + group.bench_function("shipyard", |b| { |
| 99 | + let mut bench = shipyard::heavy_compute::Benchmark::new(); |
| 100 | + b.iter(move || bench.run()); |
| 101 | + }); |
| 102 | +} |
| 103 | + |
| 104 | +fn bench_add_remove(c: &mut Criterion) { |
| 105 | + let mut group = c.benchmark_group("add_remove_component"); |
| 106 | + group.bench_function("legion", |b| { |
| 107 | + let mut bench = legion::add_remove::Benchmark::new(); |
| 108 | + b.iter(move || bench.run()); |
| 109 | + }); |
| 110 | + group.bench_function("legion_0.2.4", |b| { |
| 111 | + let mut bench = legion_2_4::add_remove::Benchmark::new(); |
| 112 | + b.iter(move || bench.run()); |
| 113 | + }); |
| 114 | + group.bench_function("shipyard", |b| { |
| 115 | + let mut bench = shipyard::add_remove::Benchmark::new(); |
| 116 | + b.iter(move || bench.run()); |
| 117 | + }); |
| 118 | + |
| 119 | + // todo Bevy appears to crash in this benchmark |
| 120 | + // group.bench_function("bevy", |b| { |
| 121 | + // let mut bench = bevy::add_remove::Benchmark::new(); |
| 122 | + // b.iter(move || bench.run()); |
| 123 | + // }); |
| 124 | +} |
| 125 | + |
| 126 | +fn bench_serialize_text(c: &mut Criterion) { |
| 127 | + let mut group = c.benchmark_group("serialize_text"); |
| 128 | + group.bench_function("legion", |b| { |
| 129 | + let mut bench = legion::serialize_text::Benchmark::new(); |
| 130 | + b.iter(move || bench.run()); |
| 131 | + }); |
| 132 | + // group.bench_function("bevy", |b| { |
| 133 | + // let mut bench = bevy::serialize_text::Benchmark::new(); |
| 134 | + // b.iter(move || bench.run()); |
| 135 | + // }); |
| 136 | +} |
| 137 | + |
| 138 | +fn bench_serialize_binary(c: &mut Criterion) { |
| 139 | + let mut group = c.benchmark_group("serialize_binary"); |
| 140 | + group.bench_function("legion", |b| { |
| 141 | + let mut bench = legion::serialize_binary::Benchmark::new(); |
| 142 | + b.iter(move || bench.run()); |
| 143 | + }); |
| 144 | + // group.bench_function("bevy", |b| { |
| 145 | + // let mut bench = bevy::serialize_text::Benchmark::new(); |
| 146 | + // b.iter(move || bench.run()); |
| 147 | + // }); |
| 148 | +} |
| 149 | + |
| 150 | +criterion_group!( |
| 151 | + benchmarks, |
| 152 | + bench_simple_insert, |
| 153 | + bench_simple_iter, |
| 154 | + bench_frag_iter_bc, |
| 155 | + bench_schedule, |
| 156 | + bench_heavy_compute, |
| 157 | + bench_add_remove, |
| 158 | + bench_serialize_text, |
| 159 | + bench_serialize_binary, |
| 160 | +); |
| 161 | +criterion_main!(benchmarks); |
0 commit comments