diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-08-11 22:11:31 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-11 22:42:19 -0700 |
| commit | 4c728f8fe72ddd4dbce579f275931848ae5cc40b (patch) | |
| tree | 0ed95145218c49c821a980776bb04c9696949efd | |
| parent | 726c9f2c807c98e2ad5bdca356d76b86195d738f (diff) | |
| parent | 86191e2014225d62cc5c3b48e990529ea354f61b (diff) | |
| download | rust-4c728f8fe72ddd4dbce579f275931848ae5cc40b.tar.gz rust-4c728f8fe72ddd4dbce579f275931848ae5cc40b.zip | |
rollup merge of #27636: llogiq/patch-1
See line 181: The lookup should start with the random index and iterate from there. Also locked stdout (which makes it a bit faster on my machine). And the `make_lookup` function now uses `map` (as the TODO asked for). Perhaps the multi-thread output from the fasta benchmark could be used to speed it up even more.
| -rw-r--r-- | src/test/bench/shootout-fasta-redux.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 3f3c9e52220..f7e6149eeaa 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -87,16 +87,12 @@ static HOMO_SAPIENS: [AminoAcid;4] = [ AminoAcid { c: 't' as u8, p: 0.3015094502008 }, ]; -// FIXME: Use map(). fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> { - let mut result = Vec::new(); let mut p = 0f32; - for a_i in a { - let mut a_i = *a_i; - p += a_i.p; - a_i.p = p * LOOKUP_SCALE; - result.push(a_i); - } + let mut result: Vec<AminoAcid> = a.iter().map(|a_i| { + p += a_i.p; + AminoAcid { c: a_i.c, p: p * LOOKUP_SCALE } + }).collect(); let result_len = result.len(); result[result_len - 1].p = LOOKUP_SCALE; result @@ -177,17 +173,17 @@ impl<'a, W: Write> RandomFasta<'a, W> { fn rng(&mut self, max: f32) -> f32 { self.seed = (self.seed * IA + IC) % IM; - max * (self.seed as f32) / (IM as f32) + (max * self.seed as f32) / (IM as f32) } fn nextc(&mut self) -> u8 { - let r = self.rng(1.0); - for a in &self.lookup[..] { - if a.p >= r { - return a.c; + let r = self.rng(LOOKUP_SCALE); + for i in (r as usize..LOOKUP_SIZE) { + if self.lookup[i].p >= r { + return self.lookup[i].c; } } - 0 + unreachable!(); } fn make(&mut self, n: usize) -> io::Result<()> { @@ -216,8 +212,9 @@ fn main() { } else { 5 }; - - let mut out = io::stdout(); + + let stdout = io::stdout(); + let mut out = stdout.lock(); out.write_all(b">ONE Homo sapiens alu\n").unwrap(); { |
