add benchmark for cloning the board

This commit is contained in:
Max Känner 2024-10-10 20:03:31 +02:00
parent 55050d5451
commit 2b0b97cba8

View File

@ -112,9 +112,75 @@ fn bench_standard_random_moves(c: &mut Criterion) {
});
}
fn bench_board_clone(c: &mut Criterion) {
let board = battlesnake::Board {
height: 11,
width: 11,
food: vec![Coord { x: 5, y: 5 }],
snakes: vec![
battlesnake::Battlesnake {
id: "1".to_owned(),
name: "1".to_owned(),
health: 100,
body: vec![Coord { x: 5, y: 1 }; 3],
head: Coord { x: 5, y: 1 },
length: 3,
latency: "0".to_owned(),
shout: None,
squad: String::new(),
},
battlesnake::Battlesnake {
id: "2".to_owned(),
name: "2".to_owned(),
health: 100,
body: vec![Coord { x: 5, y: 9 }; 3],
head: Coord { x: 5, y: 9 },
length: 3,
latency: "0".to_owned(),
shout: None,
squad: String::new(),
},
battlesnake::Battlesnake {
id: "3".to_owned(),
name: "3".to_owned(),
health: 100,
body: vec![Coord { x: 1, y: 5 }; 3],
head: Coord { x: 1, y: 5 },
length: 3,
latency: "0".to_owned(),
shout: None,
squad: String::new(),
},
battlesnake::Battlesnake {
id: "4".to_owned(),
name: "4".to_owned(),
health: 100,
body: vec![Coord { x: 9, y: 5 }; 3],
head: Coord { x: 9, y: 5 },
length: 3,
latency: "0".to_owned(),
shout: None,
squad: String::new(),
},
],
hazards: vec![],
};
let token_map = SnakeToken::from_board(&board);
let mut board =
battlesnake::simulation::Board::from_game_board(&board, &token_map, 0, 12, 1, false);
let mut rng = StdRng::seed_from_u64(0);
board.simulate_until(&mut rng, |board| board.turn() > 25);
c.bench_function("board clone", |b| {
b.iter(|| board.clone());
});
}
criterion_group!(
benches,
bench_duel_random_moves,
bench_standard_random_moves
bench_standard_random_moves,
bench_board_clone,
);
criterion_main!(benches);