The Computer Language
Benchmarks Game

regex-redux Rust #3 program

source code

// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// contributed by Francois Green

extern crate rayon;
extern crate regex;

use rayon::prelude::*;
use std::io::{self, Read};
use std::thread;

macro_rules! regex { ($re:expr) => { ::regex::bytes::Regex::new($re).unwrap() } }

fn main() {
    let mut input = Vec::with_capacity(51 * (1 << 20));

    io::stdin().read_to_end(&mut input).unwrap();

    let sequence = regex!(">[^\n]*\n|\n").replace_all(&input, &b""[..]).into_owned();

    let seq_copy = sequence.clone();

    let result = thread::spawn(move || {
        vec![
            ("tHa[Nt]", &b"<4>"[..]),
            ("aND|caN|Ha[DS]|WaS", &b"<3>"[..]),
            ("a[NSt]|BY", &b"<2>"[..]),
            ("<[^>]*>", &b"|"[..]),
            ("\\|[^|][^|]*\\|", &b"-"[..]),
        ].iter()
         .fold(seq_copy, |mut buf, &(re, replacement)| {
             regex!(re).replace_all(&mut buf, replacement).into_owned()
         })
    });

    vec![
        "agggtaaa|tttaccct",
        "[cgt]gggtaaa|tttaccc[acg]",
        "a[act]ggtaaa|tttacc[agt]t",
        "ag[act]gtaaa|tttac[agt]ct",
        "agg[act]taaa|ttta[agt]cct",
        "aggg[acg]aaa|ttt[cgt]ccct",
        "agggt[cgt]aa|tt[acg]accct",
        "agggta[cgt]a|t[acg]taccct",
        "agggtaa[cgt]|[acg]ttaccct",
    ].par_iter()
     .for_each(|v| println!("{} {}", v.to_string(), regex!(v).find_iter(&sequence).count()));

    println!("\n{} \n{} \n{:?}", input.len(), sequence.len(), result.join().unwrap().len());
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
rustc 1.25.0 (84203cac6 2018-03-25)


Thu, 29 Mar 2018 17:09:25 GMT

MAKE:
/opt/src/rust-1.25.0/bin/rustc -C opt-level=3 -C target-cpu=core2 -C lto -C codegen-units=1 -L /opt/src/rust-libs regexredux.rs -o regexredux.rust-3.rust_run
error[E0460]: found possibly newer version of crate `lazy_static` which `rayon` depends on
 --> regexredux.rs:6:1
  |
6 | extern crate rayon;
  | ^^^^^^^^^^^^^^^^^^^
  |
  = note: perhaps that crate needs to be recompiled?
  = note: the following crate versions were found:
          crate `lazy_static`: /opt/src/rust-1.25.0/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblazy_static-c2718c97cbc91f7c.rlib
          crate `lazy_static`: /opt/src/rust-libs/liblazy_static-cc3614442e8d4ac5.rlib
          crate `rayon`: /opt/src/rust-libs/librayon-3db3bc39e5457432.rlib

error: aborting due to previous error

/home/dunham/benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:632: recipe for target 'regexredux.rust-3.rust_run' failed
make: [regexredux.rust-3.rust_run] Error 101 (ignored)

0.18s to complete and log all make actions

COMMAND LINE:
./regexredux.rust-3.rust_run 0 < regexredux-input50000.txt

MAKE ERROR