Skip to content

Commit

Permalink
parallelisation of shootout-k-nucleotide
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXitoi committed Apr 17, 2014
1 parent 8a4ffbf commit ba99e4c
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/test/bench/shootout-k-nucleotide.rs
Expand Up @@ -11,8 +11,12 @@
// ignore-android see #10393 #13206
// ignore-pretty

extern crate sync;

use std::strbuf::StrBuf;
use std::slice;
use sync::Arc;
use sync::Future;

static TABLE: [u8, ..4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ];
static TABLE_SIZE: uint = 2 << 16;
Expand Down Expand Up @@ -202,10 +206,9 @@ fn unpack_symbol(c: u8) -> u8 {
TABLE[c as uint]
}

fn generate_frequencies(frequencies: &mut Table,
mut input: &[u8],
frame: uint) {
if input.len() < frame { return; }
fn generate_frequencies(mut input: &[u8], frame: uint) -> Table {
let mut frequencies = Table::new();
if input.len() < frame { return frequencies; }
let mut code = Code(0);

// Pull first frame.
Expand All @@ -220,6 +223,7 @@ fn generate_frequencies(frequencies: &mut Table,
frequencies.lookup(code, BumpCallback);
input = input.slice_from(1);
}
frequencies
}

fn print_frequencies(frequencies: &Table, frame: uint) {
Expand Down Expand Up @@ -266,20 +270,21 @@ fn main() {
} else {
get_sequence(&mut std::io::stdin(), ">THREE")
};

let mut frequencies = Table::new();
generate_frequencies(&mut frequencies, input.as_slice(), 1);
print_frequencies(&frequencies, 1);

frequencies = Table::new();
generate_frequencies(&mut frequencies, input.as_slice(), 2);
print_frequencies(&frequencies, 2);

for occurrence in OCCURRENCES.iter() {
frequencies = Table::new();
generate_frequencies(&mut frequencies,
input.as_slice(),
occurrence.len());
print_occurrences(&mut frequencies, *occurrence);
let input = Arc::new(input);

let nb_freqs: Vec<(uint, Future<Table>)> = range(1u, 3).map(|i| {
let input = input.clone();
(i, Future::spawn(proc() generate_frequencies(input.as_slice(), i)))
}).collect();
let occ_freqs: Vec<Future<Table>> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
Future::spawn(proc() generate_frequencies(input.as_slice(), occ.len()))
}).collect();

for (i, freq) in nb_freqs.move_iter() {
print_frequencies(&freq.unwrap(), i);
}
for (&occ, freq) in OCCURRENCES.iter().zip(occ_freqs.move_iter()) {
print_occurrences(&mut freq.unwrap(), occ);
}
}

5 comments on commit ba99e4c

@bors
Copy link
Contributor

@bors bors commented on ba99e4c Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at TeXitoi@ba99e4c

@bors
Copy link
Contributor

@bors bors commented on ba99e4c Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging TeXitoi/rust/shootout-knucleotide-parallel = ba99e4c into auto

@bors
Copy link
Contributor

@bors bors commented on ba99e4c Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeXitoi/rust/shootout-knucleotide-parallel = ba99e4c merged ok, testing candidate = 0c23140

@bors
Copy link
Contributor

@bors bors commented on ba99e4c Apr 18, 2014

@bors
Copy link
Contributor

@bors bors commented on ba99e4c Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0c23140

Please sign in to comment.