1 // The Computer Language Benchmarks Game
2 // http://benchmarksgame.alioth.debian.org/
4 // contributed by the Rust Project Developers
6 // Copyright (c) 2014 The Rust Project Developers
8 // All rights reserved.
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
14 // - Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
17 // - Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in
19 // the documentation and/or other materials provided with the
22 // - Neither the name of "The Computer Language Benchmarks Game" nor
23 // the name of "The Computer Language Shootout Benchmarks" nor the
24 // names of its contributors may be used to endorse or promote
25 // products derived from this software without specific prior
26 // written permission.
28 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 // OF THE POSSIBILITY OF SUCH DAMAGE.
42 // ignore-cross-compile #12102
44 #![feature(macro_rules, phase, slicing_syntax)]
47 #[phase(plugin)]extern crate regex_macros;
50 use regex::{NoExpand, Regex};
51 use std::sync::{Arc, Future};
53 fn count_matches(seq: &str, variant: &Regex) -> int {
55 for _ in variant.find_iter(seq) {
62 let mut rdr = if std::os::getenv("RUST_BENCH").is_some() {
63 let fd = io::File::open(&Path::new("shootout-k-nucleotide.data"));
64 box io::BufferedReader::new(fd) as Box<io::Reader>
66 box io::stdin() as Box<io::Reader>
68 let mut seq = rdr.read_to_string().unwrap();
71 seq = regex!(">[^\n]*\n|\n").replace_all(seq.as_slice(), NoExpand(""));
72 let seq_arc = Arc::new(seq.clone()); // copy before it moves
75 let mut seqlen = Future::spawn(move|| {
77 (regex!("B"), "(c|g|t)"),
78 (regex!("D"), "(a|g|t)"),
79 (regex!("H"), "(a|c|t)"),
80 (regex!("K"), "(g|t)"),
81 (regex!("M"), "(a|c)"),
82 (regex!("N"), "(a|c|g|t)"),
83 (regex!("R"), "(a|g)"),
84 (regex!("S"), "(c|g)"),
85 (regex!("V"), "(a|c|g)"),
86 (regex!("W"), "(a|t)"),
87 (regex!("Y"), "(c|t)"),
90 for (re, replacement) in substs.into_iter() {
91 seq = re.replace_all(seq.as_slice(), NoExpand(replacement));
97 regex!("agggtaaa|tttaccct"),
98 regex!("[cgt]gggtaaa|tttaccc[acg]"),
99 regex!("a[act]ggtaaa|tttacc[agt]t"),
100 regex!("ag[act]gtaaa|tttac[agt]ct"),
101 regex!("agg[act]taaa|ttta[agt]cct"),
102 regex!("aggg[acg]aaa|ttt[cgt]ccct"),
103 regex!("agggt[cgt]aa|tt[acg]accct"),
104 regex!("agggta[cgt]a|t[acg]taccct"),
105 regex!("agggtaa[cgt]|[acg]ttaccct"),
107 let (mut variant_strs, mut counts) = (vec!(), vec!());
108 for variant in variants.into_iter() {
109 let seq_arc_copy = seq_arc.clone();
110 variant_strs.push(variant.to_string());
111 counts.push(Future::spawn(move|| {
112 count_matches(seq_arc_copy.as_slice(), &variant)
116 for (i, variant) in variant_strs.iter().enumerate() {
117 println!("{} {}", variant, counts[i].get());
120 println!("{}", ilen);
121 println!("{}", clen);
122 println!("{}", seqlen.get());