Skip to content

Commit

Permalink
Rename to benchmark.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
iMilchshake committed Aug 14, 2024
1 parent 8be5a40 commit c8b84f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name = "check_generator"
name = "automap_test"

[[bin]]
name = "map_test"
name = "benchmark"

[dependencies]
# egui-macroquad = { git = "https://github.com/optozorax/egui-macroquad", default-features = false, rev="dfbdb967d6cf4e4726b84a568ec1b2bdc7e4f492" }
Expand Down
30 changes: 14 additions & 16 deletions src/bin/map_test.rs → src/bin/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
use std::collections::HashMap;
use std::panic;
use gores_mapgen::config::{GenerationConfig, MapConfig};
use gores_mapgen::generator::Generator;
use gores_mapgen::random::Seed;
use rand::prelude::*;
use std::collections::HashMap;
use std::panic;
use std::time::Instant;


fn main() {

//thanks tobi for the code hehehe
let init_gen_configs: HashMap<String, GenerationConfig> = GenerationConfig::get_all_configs();
let init_map_configs: HashMap<String, MapConfig> = MapConfig::get_all_configs();

let seed: u64 = random::<u64>();
//Loop through the keys of the hashmap
for gkey in init_gen_configs.keys(){
for mkey in init_map_configs.keys(){
//Loop through the keys of the hashmap
for gkey in init_gen_configs.keys() {
for mkey in init_map_configs.keys() {
//We access the generate_map arguments now so the time from instant is only timing the generation function and not retreiving the data for the var also.
let seed = Seed::from_u64(seed);
let gen_cfg = init_gen_configs.get(gkey).unwrap();
let map_cfg = init_map_configs.get(mkey).unwrap();

let now = Instant::now();
let _ = panic::catch_unwind(|| {
let gen_result = Generator::generate_map(
200_000,
&seed,
gen_cfg,
map_cfg
);
let gen_result = Generator::generate_map(200_000, &seed, gen_cfg, map_cfg);
let elapsed = now.elapsed(); //compare the time difference
match gen_result { //Handiling the Result<t,e>
Ok(_) => println!("GEN {gkey} WITH {mkey} MAP GEN | ELAPSED TIME: {elapsed:?\n}"),
Err(e) => println!("ERROR IN GENERATING MAP: {e} | GENERATION THAT FAILED: {gkey} with {mkey}"),
match gen_result {
//Handiling the Result<t,e>
Ok(_) => {
println!("GEN {gkey} WITH {mkey} MAP GEN | ELAPSED TIME: {elapsed:?\n}")
}
Err(e) => println!(
"ERROR IN GENERATING MAP: {e} | GENERATION THAT FAILED: {gkey} with {mkey}"
),
}
});
}
Expand Down

0 comments on commit c8b84f2

Please sign in to comment.