Warn when trying to run an unoptimised executable

Thu, 01 Dec 2022 23:46:09 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 01 Dec 2022 23:46:09 +0200
changeset 5
df971c81282e
parent 0
eb3c7813b67a
child 6
bcb508479948

Warn when trying to run an unoptimised executable

src/main.rs file | annotate | diff | comparison | revisions
--- a/src/main.rs	Thu Dec 01 23:07:35 2022 +0200
+++ b/src/main.rs	Thu Dec 01 23:46:09 2022 +0200
@@ -15,12 +15,13 @@
 use clap::Parser;
 use itertools::Itertools;
 use serde_json;
+use std::num::NonZeroUsize;
+
 use alg_tools::iterate::Verbose;
 use alg_tools::parallelism::{
     set_num_threads,
     set_max_threads,
 };
-use std::num::NonZeroUsize;
 
 pub mod types;
 pub mod measures;
@@ -198,6 +199,18 @@
 pub fn main() {
     let cli = CommandLineArgs::parse();
 
+    #[cfg(debug_assertions)]
+    {
+        use colored::Colorize;
+        println!("{}", format!("\n\
+            ********\n\
+            WARNING: Compiled without optimisations; {}\n\
+            Please recompile with `--release` flag.\n\
+            ********\n\
+            ", "performance will be poor!".blink()
+        ).red());
+    }
+
     if let Some(n_threads) = cli.num_threads {
         let n = NonZeroUsize::new(n_threads).expect("Invalid thread count");
         set_num_threads(n);

mercurial