js/src/jit-test/tests/sunspider/check-string-fasta.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial