Skip to content

Commit cd1a765

Browse files
committed
Add Peter Hull's contributed translation of the fasta shootout benchmark (integer-only version).
1 parent e270ab6 commit cd1a765

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ Matt Brubeck <[email protected]>
1717
Michael Bebenita <[email protected]>
1818
Or Brostovski <[email protected]>
1919
Patrick Walton <[email protected]>
20+
Peter Hull <[email protected]>
2021
Ralph Giles <[email protected]>
2122
Roy Frostig <[email protected]>

src/test/bench/shootout/binary-trees.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
type tree = tag(nil(), node(@tree, @tree, int));
1+
tag tree {
2+
nil();
3+
node(@tree, @tree, int);
4+
}
25

36
fn item_check(&tree t) -> int {
47
alt (t) {

src/test/bench/shootout/fasta.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* -*- mode: rust; indent-tabs-mode: nil -*-
2+
* Implementation of 'fasta' benchmark from
3+
* Computer Language Benchmarks Game
4+
* http://shootout.alioth.debian.org/
5+
*/
6+
use std;
7+
import std._vec;
8+
import std._str;
9+
import std._uint;
10+
import std._int;
11+
12+
fn LINE_LENGTH() -> uint {
13+
ret 60u;
14+
}
15+
16+
obj myrandom(mutable u32 last) {
17+
fn next(u32 mx) -> u32 {
18+
last = (last * 3877u32 + 29573u32) % 139968u32;
19+
auto ans = (mx*last) / 139968u32;
20+
ret ans;
21+
}
22+
}
23+
24+
type aminoacids = tup(char, u32);
25+
26+
fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
27+
let u32 cp = 0u32;
28+
let vec[aminoacids] ans = vec();
29+
for (aminoacids a in aa) {
30+
cp += a._1;
31+
ans += tup(a._0, cp);
32+
}
33+
ret ans;
34+
}
35+
36+
fn select_random(u32 r, vec[aminoacids] genelist) -> char {
37+
if (r < genelist.(0)._1) {
38+
ret genelist.(0)._0;
39+
}
40+
fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
41+
if (hi > (lo + 1u)) {
42+
let uint mid = lo + (hi - lo) / 2u;
43+
if (target < v.(mid)._1) {
44+
be bisect(v, lo, mid, target);
45+
}
46+
else {
47+
be bisect(v, mid, hi, target);
48+
}
49+
}
50+
else {
51+
ret v.(hi)._0;
52+
}
53+
}
54+
ret bisect(genelist, 0u, _vec.len[aminoacids](genelist) - 1u, r);
55+
}
56+
57+
fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
58+
log(">" + id + " " + desc);
59+
auto rng = myrandom(std.rand.mk_rng().next());
60+
let str op = "";
61+
for each (uint i in _uint.range(0u, n as uint)) {
62+
op += select_random(rng.next(100u32), genelist) as u8;
63+
if (_str.byte_len(op) >= LINE_LENGTH()) {
64+
log(op);
65+
op = "";
66+
}
67+
}
68+
if (_str.byte_len(op) > 0u) {
69+
log(op);
70+
}
71+
}
72+
73+
fn make_repeat_fasta(str id, str desc, str s, int n) {
74+
log(">" + id + " " + desc);
75+
let str op = "";
76+
let uint sl = _str.byte_len(s);
77+
for each (uint i in _uint.range(0u, n as uint)) {
78+
79+
op += s.(i % sl);
80+
if (_str.byte_len(op) >= LINE_LENGTH()) {
81+
log(op);
82+
op = "";
83+
}
84+
}
85+
if (_str.byte_len(op) > 0u) {
86+
log(op);
87+
}
88+
}
89+
90+
fn main(vec[str] args) {
91+
let vec[aminoacids] iub = make_cumulative(vec(tup( 'a', 27u32 ),
92+
tup( 'c', 12u32 ),
93+
tup( 'g', 12u32 ),
94+
tup( 't', 27u32 ),
95+
96+
tup( 'B', 2u32 ),
97+
tup( 'D', 2u32 ),
98+
tup( 'H', 2u32 ),
99+
tup( 'K', 2u32 ),
100+
tup( 'M', 2u32 ),
101+
tup( 'N', 2u32 ),
102+
tup( 'R', 2u32 ),
103+
tup( 'S', 2u32 ),
104+
tup( 'V', 2u32 ),
105+
tup( 'W', 2u32 ),
106+
tup( 'Y', 2u32 )));
107+
108+
let vec[aminoacids] homosapiens = make_cumulative(vec(tup( 'a', 30u32 ),
109+
tup( 'c', 20u32 ),
110+
tup( 'g', 20u32 ),
111+
tup( 't', 30u32 )));
112+
113+
let str alu =
114+
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
115+
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
116+
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
117+
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
118+
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
119+
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
120+
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
121+
122+
let int n = 512;
123+
124+
make_repeat_fasta ("ONE", "Homo sapiens alu", alu, n*2);
125+
make_random_fasta("TWO", "IUB ambiguity codes", iub, n*3);
126+
make_random_fasta ("THREE", "Homo sapiens frequency", homosapiens, n*5);
127+
}

0 commit comments

Comments
 (0)