PageRenderTime 26ms CodeModel.GetById 8ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/js/src/metrics/jint/sunspider/string-fasta.js

http://github.com/zpao/v8monkey
JavaScript | 95 lines | 70 code | 11 blank | 14 comment | 11 complexity | f225e9eda5edea06b2e858d667f3552f MD5 | raw file
 1// The Great Computer Language Shootout
 2//  http://shootout.alioth.debian.org
 3//
 4//  Contributed by Ian Osgood
 5
 6var last = 42, A = 3877, C = 29573, M = 139968;
 7
 8function rand(max) {
 9  last = (last * A + C) % M;
10  return max * last / M;
11}
12
13var ALU =
14  "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
15  "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
16  "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
17  "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
18  "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
19  "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
20  "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
21
22var IUB = {
23  a:0.27, c:0.12, g:0.12, t:0.27,
24  B:0.02, D:0.02, H:0.02, K:0.02,
25  M:0.02, N:0.02, R:0.02, S:0.02,
26  V:0.02, W:0.02, Y:0.02
27}
28
29var HomoSap = {
30  a: 0.3029549426680,
31  c: 0.1979883004921,
32  g: 0.1975473066391,
33  t: 0.3015094502008
34}
35
36function makeCumulative(table) {
37  var last = null;
38  /* BEGIN LOOP */
39  for (var c in table) {
40    if (last) table[c] += table[last];
41    last = c;
42  }
43  /* END LOOP */
44}
45
46function fastaRepeat(n, seq) {
47  var seqi = 0, lenOut = 60;
48  /* BEGIN LOOP */
49  while (n>0) {
50    if (n<lenOut) lenOut = n;
51    if (seqi + lenOut < seq.length) {
52      ret = seq.substring(seqi, seqi+lenOut);
53      seqi += lenOut;
54    } else {
55      var s = seq.substring(seqi);
56      seqi = lenOut - s.length;
57      ret = s + seq.substring(0, seqi);
58    }
59    n -= lenOut;
60  }
61  /* END LOOP */
62}
63
64function fastaRandom(n, table) {
65  var line = new Array(60);
66  makeCumulative(table);
67  /* BEGIN LOOP */
68  while (n>0) {
69    if (n<line.length) line = new Array(n);
70  /* BEGIN LOOP */
71    for (var i=0; i<line.length; i++) {
72      var r = rand(1);
73  /* BEGIN LOOP */
74      for (var c in table) {
75        if (r < table[c]) {
76          line[i] = c;
77          break;
78        }
79      }
80  /* END LOOP */
81    }
82  /* END LOOP */
83    ret = line.join('');
84    n -= line.length;
85  }
86  /* END LOOP */
87}
88
89var ret;
90
91var count = 7;
92ret = fastaRepeat(2*count*100000, ALU);
93ret = fastaRandom(3*count*1000, IUB);
94ret = fastaRandom(5*count*1000, HomoSap);
95