Fix panic behaviour
@@ -2,6 +2,7 @@ use std::fs;
use std::path::Path;
use std::collections::HashSet;
use std::time::{Duration, Instant};
+use std::panic;
use walkdir::WalkDir;
use syn::{Item, Expr, ImplItem, Stmt, ExprArray, ExprCall, ExprMethodCall, Visibility, Ident, Type,
@@ -57,12 +58,17 @@ fn main() {
if combs.is_empty() {
break;
}
+ count += combs.len();
combs.into_par_iter().for_each(|comb| {
+ let res = panic::catch_unwind(|| {
let concatenated = comb.into_iter().flatten().cloned().collect::<Vec<_>>();
let s = String::from_utf8(concatenated).unwrap();
test(&s);
});
- count += BATCH_SIZE;
+ if let Err(e) = res {
+ eprintln!("Panic during execution in thread:\n {:?}", e);
+ }
+ });
println!("{}", count);
}
}
@@ -89,6 +95,9 @@ fn test(pattern: &str) {
array[[0, i]] = n as f64;
array[[1, i]] = dur.as_micros() as f64;
if dur.as_millis() > MAX_MILLIS {
+ if i == 0 || i == 1 {
+ print_find(pattern, &array, 0.0);
+ }
break;
}
}
@@ -113,7 +122,13 @@ fn test(pattern: &str) {
let stddev = slopes.central_moment(2).unwrap().sqrt();
//println!("{:<30}{}", stddev, pattern);
+ //println!("{}", array);
if stddev > ACCEPTANCE_STDDEV {
+ print_find(pattern, &array, stddev);
+ }
+}
+
+fn print_find(pattern: &str, array: &Array2<f64>, stddev: f64) {
println!("
possible non-linear behaviour found
pattern: {:?}
@@ -122,7 +137,6 @@ standard deviation: {}
\
", pattern, array.t(), stddev);
}
-}
fn test_single(s: &str) -> Duration {
let parser = Parser::new_ext(&s, Options::all());
