Simplified duration handling to allow longer profiling
authorJustin Worthe <justin@worthe-it.co.za>
Sat, 21 Jul 2018 18:40:40 +0000 (20:40 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sat, 21 Jul 2018 18:40:40 +0000 (20:40 +0200)
Makefile
src/bin/perf-test.rs
src/engine/constants.rs
src/main.rs

index 8b630d0..42ce706 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ bench:
        cargo run --release --features "benchmarking" --bin perf-test
 
 profile:
-       cargo build --release --features "benchmarking single-threaded"
+       cargo build --release --features "benchmarking single-threaded extended-time"
        mkdir -p target/profile
        perf record -g target/release/perf-test
        perf script > target/profile/out.perf
index d4eae32..8d6a490 100644 (file)
@@ -3,6 +3,7 @@ extern crate time;
 use time::{PreciseTime, Duration};
 
 use zombot::*;
+use zombot::engine::constants::*;
 
 const STATE_PATH: &str = "tests/state0.json";
 
@@ -22,7 +23,7 @@ fn _expressive() {
             process::exit(1);
         }
     };
-    let max_time = Duration::milliseconds(1950);
+    let max_time = Duration::milliseconds(MAX_TIME_MILLIS);
     strategy::monte_carlo::choose_move(&settings, &state, &start_time, max_time);
 }
 
@@ -36,6 +37,6 @@ fn bitwise() {
             process::exit(1);
         }
     };
-    let max_time = Duration::milliseconds(1950);
+    let max_time = Duration::milliseconds(MAX_TIME_MILLIS);
     strategy::monte_carlo::choose_move(&settings, &state, &start_time, max_time);
 }
index 9805f72..8453a54 100644 (file)
@@ -27,3 +27,14 @@ pub const ENERGY_PRICE: u16 = 20;
 pub const ENERGY_CONSTRUCTION_TIME: u8 = 1;
 
 pub const DECONSTRUCT_ENERGY: u16 = 5;
+
+
+#[cfg(not(feature = "reduced-time"))]
+#[cfg(not(feature = "extended-time"))]
+pub const MAX_TIME_MILLIS: i64 = 1950;
+
+#[cfg(feature = "reduced-time")]
+pub const MAX_TIME_MILLIS: i64 = 950;
+
+#[cfg(feature = "extended-time")]
+pub const MAX_TIME_MILLIS: i64 = 19950;
index 752e8b9..0235d5f 100644 (file)
@@ -3,6 +3,7 @@ extern crate time;
 use time::{PreciseTime, Duration};
 
 use zombot::*;
+use zombot::engine::constants::*;
 use zombot::engine::command::Command;
 
 use std::error::Error;
@@ -16,16 +17,7 @@ use std::io::prelude::*;
 use std::process;
 
 fn choose_move<GS:engine::GameState>(settings: &engine::settings::GameSettings, state: &GS, start_time: &PreciseTime) -> Command {
-    #[cfg(not(feature = "reduced-time"))]
-    #[cfg(not(feature = "extended-time"))]
-    let max_time = Duration::milliseconds(1950);
-    
-    #[cfg(feature = "reduced-time")]
-    let max_time = Duration::milliseconds(950);
-
-    #[cfg(feature = "extended-time")]
-    let max_time = Duration::milliseconds(19950);
-    
+    let max_time = Duration::milliseconds(MAX_TIME_MILLIS);
     strategy::monte_carlo::choose_move(settings, state, start_time, max_time)
 }