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)]
49 use regex::{NoExpand, Regex};
50 use std::sync::{Arc, Future};
53 ($e:expr) => (Regex::new($e).unwrap())
56 fn count_matches(seq: &str, variant: &Regex) -> int {
58 for _ in variant.find_iter(seq) {
65 let mut rdr = if std::os::getenv("RUST_BENCH").is_some() {
66 let fd = io::File::open(&Path::new("shootout-k-nucleotide.data"));
67 box io::BufferedReader::new(fd) as Box<io::Reader>
69 box io::stdin() as Box<io::Reader>
71 let mut seq = rdr.read_to_string().unwrap();
74 seq = regex!(">[^\n]*\n|\n").replace_all(seq.as_slice(), NoExpand(""));
75 let seq_arc = Arc::new(seq.clone()); // copy before it moves
78 let mut seqlen = Future::spawn(move|| {
80 (regex!("B"), "(c|g|t)"),
81 (regex!("D"), "(a|g|t)"),
82 (regex!("H"), "(a|c|t)"),
83 (regex!("K"), "(g|t)"),
84 (regex!("M"), "(a|c)"),
85 (regex!("N"), "(a|c|g|t)"),
86 (regex!("R"), "(a|g)"),
87 (regex!("S"), "(c|g)"),
88 (regex!("V"), "(a|c|g)"),
89 (regex!("W"), "(a|t)"),
90 (regex!("Y"), "(c|t)"),
93 for (re, replacement) in substs.into_iter() {
94 seq = re.replace_all(seq.as_slice(), NoExpand(replacement));
100 regex!("agggtaaa|tttaccct"),
101 regex!("[cgt]gggtaaa|tttaccc[acg]"),
102 regex!("a[act]ggtaaa|tttacc[agt]t"),
103 regex!("ag[act]gtaaa|tttac[agt]ct"),
104 regex!("agg[act]taaa|ttta[agt]cct"),
105 regex!("aggg[acg]aaa|ttt[cgt]ccct"),
106 regex!("agggt[cgt]aa|tt[acg]accct"),
107 regex!("agggta[cgt]a|t[acg]taccct"),
108 regex!("agggtaa[cgt]|[acg]ttaccct"),
110 let (mut variant_strs, mut counts) = (vec!(), vec!());
111 for variant in variants.into_iter() {
112 let seq_arc_copy = seq_arc.clone();
113 variant_strs.push(variant.to_string());
114 counts.push(Future::spawn(move|| {
115 count_matches(seq_arc_copy.as_slice(), &variant)
119 for (i, variant) in variant_strs.iter().enumerate() {
120 println!("{} {}", variant, counts[i].get());
123 println!("{}", ilen);
124 println!("{}", clen);
125 println!("{}", seqlen.get());