[pypy-svn] r53310 - pypy/branch/js-refactoring/pypy/lang/js/bench
santagada at codespeak.net
santagada at codespeak.net
Fri Apr 4 05:18:19 CEST 2008
Author: santagada
Date: Fri Apr 4 05:18:16 2008
New Revision: 53310
Added:
pypy/branch/js-refactoring/pypy/lang/js/bench/TODO.txt (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/ackermann.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/ary.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/binarytrees.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/fannkuch.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/fasta.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/fibo.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/harmonic.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/hash.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/hash2.javascript (contents, props changed)
pypy/branch/js-refactoring/pypy/lang/js/bench/heapsort.javascript (contents, props changed)
Removed:
pypy/branch/js-refactoring/pypy/lang/js/bench/f1.js
pypy/branch/js-refactoring/pypy/lang/js/bench/f2.js
Modified:
pypy/branch/js-refactoring/pypy/lang/js/bench/ (props changed)
Log:
first import of the benchmarks, there are still more to come
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/TODO.txt
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/TODO.txt Fri Apr 4 05:18:16 2008
@@ -0,0 +1,32 @@
+All benchmarks are from The Computer Language Benchmarks Game, licensed under the revised BSD License
+
+Parameters for the benchmarks:
+
+ackermann 9,10,11
+ary 3000,5000,7000,9000
+binarytrees 12,14,16
+fannkuch 9,10,11
+fasta (substring) 250000,2500000,25000000
+fibo 12,24,32
+harmonic 6000000,8000000,10000000
+hash 40000,60000,80000,100000
+hash2 50,100,150,200
+heapsort 20000,40000,60000,80000,100000
+hello ?
+knucleotide (without one simple regex)
+lists (concat) @0
+matrix @0
+methcall @0
+nbody
+nestedloop @0
+nsieve
+nsievebits
+objinst @0
+partialsums (sin, cos, pow)
+random @0
+recursive
+sieve @0
+spectralnorm (sqrt)
+strcat @0
+sumcol (readline!)
+takfp @0
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/ackermann.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/ackermann.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,15 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by Sjoerd Visscher
+
+function ack(m, n) {
+ return (m == 0
+ ? n + 1
+ : (n == 0
+ ? ack(m - 1, 1)
+ : ack(m - 1, ack(m, n - 1))));
+}
+
+var n = arguments[0];
+print("ack(3, " + n + "): " + ack(3, n));
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/ary.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/ary.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,23 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by David Hedbor
+// modified by Isaac Gouy
+
+var i, k;
+
+var n = arguments[0];
+var x = Array(n);
+var y = Array(n);
+
+for (i = 0; i < n; i++) {
+ x[i] = i + 1;
+ y[i] = 0; // Need to set all entries in i to zero or the result will be NaN
+}
+for (k = 0 ; k < 1000; k++) {
+ for (i = n-1; i >= 0; i--) {
+ y[i] += x[i];
+ }
+}
+print(y[0], y[n-1]);
+
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/binarytrees.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/binarytrees.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,51 @@
+/* The Great Computer Language Shootout
+ http://shootout.alioth.debian.org/
+ contributed by Isaac Gouy */
+
+function TreeNode(left,right,item){
+ this.left = left;
+ this.right = right;
+ this.item = item;
+}
+
+TreeNode.prototype.itemCheck = function(){
+ if (this.left==null) return this.item;
+ else return this.item + this.left.itemCheck() - this.right.itemCheck();
+}
+
+function bottomUpTree(item,depth){
+ if (depth>0){
+ return new TreeNode(
+ bottomUpTree(2*item-1, depth-1)
+ ,bottomUpTree(2*item, depth-1)
+ ,item
+ );
+ }
+ else {
+ return new TreeNode(null,null,item);
+ }
+}
+
+
+var minDepth = 4;
+var n = arguments[0];
+var maxDepth = Math.max(minDepth + 2, n);
+var stretchDepth = maxDepth + 1;
+
+var check = bottomUpTree(0,stretchDepth).itemCheck();
+print("stretch tree of depth " + stretchDepth + "\t check: " + check);
+
+var longLivedTree = bottomUpTree(0,maxDepth);
+for (var depth=minDepth; depth<=maxDepth; depth+=2){
+ var iterations = 1 << (maxDepth - depth + minDepth);
+
+ check = 0;
+ for (var i=1; i<=iterations; i++){
+ check += bottomUpTree(i,depth).itemCheck();
+ check += bottomUpTree(-i,depth).itemCheck();
+ }
+ print(iterations*2 + "\t trees of depth " + depth + "\t check: " + check);
+}
+
+print("long lived tree of depth " + maxDepth + "\t check: "
+ + longLivedTree.itemCheck());
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/fannkuch.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/fannkuch.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,66 @@
+/* The Great Computer Language Shootout
+ http://shootout.alioth.debian.org/
+ contributed by Isaac Gouy */
+
+function fannkuch(n) {
+ var check = 0;
+ var perm = Array(n);
+ var perm1 = Array(n);
+ var count = Array(n);
+ var maxPerm = Array(n);
+ var maxFlipsCount = 0;
+ var m = n - 1;
+
+ for (var i = 0; i < n; i++) perm1[i] = i;
+ var r = n;
+
+ while (true) {
+ // write-out the first 30 permutations
+ if (check < 30){
+ var s = "";
+ for(var i=0; i<n; i++) s += (perm1[i]+1).toString();
+ print(s);
+ check++;
+ }
+
+ while (r != 1) { count[r - 1] = r; r--; }
+ if (!(perm1[0] == 0 || perm1[m] == m)) {
+ for (var i = 0; i < n; i++) perm[i] = perm1[i];
+
+ var flipsCount = 0;
+ var k;
+
+ while (!((k = perm[0]) == 0)) {
+ var k2 = (k + 1) >> 1;
+ for (var i = 0; i < k2; i++) {
+ var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp;
+ }
+ flipsCount++;
+ }
+
+ if (flipsCount > maxFlipsCount) {
+ maxFlipsCount = flipsCount;
+ for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];
+ }
+ }
+
+ while (true) {
+ if (r == n) return maxFlipsCount;
+ var perm0 = perm1[0];
+ var i = 0;
+ while (i < r) {
+ var j = i + 1;
+ perm1[i] = perm1[j];
+ i = j;
+ }
+ perm1[r] = perm0;
+
+ count[r] = count[r] - 1;
+ if (count[r] > 0) break;
+ r++;
+ }
+ }
+}
+
+var n = arguments[0];
+print("Pfannkuchen(" + n + ") = " + fannkuch(n));
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/fasta.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/fasta.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,88 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org
+//
+// Contributed by Ian Osgood
+
+var last = 42, A = 3877, C = 29573, M = 139968;
+
+function rand(max) {
+ last = (last * A + C) % M;
+ return max * last / M;
+}
+
+var ALU =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
+
+var IUB = {
+ a:0.27, c:0.12, g:0.12, t:0.27,
+ B:0.02, D:0.02, H:0.02, K:0.02,
+ M:0.02, N:0.02, R:0.02, S:0.02,
+ V:0.02, W:0.02, Y:0.02
+}
+
+var HomoSap = {
+ a: 0.3029549426680,
+ c: 0.1979883004921,
+ g: 0.1975473066391,
+ t: 0.3015094502008
+}
+
+function makeCumulative(table) {
+ var last = null;
+ for (var c in table) {
+ if (last) table[c] += table[last];
+ last = c;
+ }
+}
+
+function fastaRepeat(n, seq) {
+ var seqi = 0, lenOut = 60;
+ while (n>0) {
+ if (n<lenOut) lenOut = n;
+ if (seqi + lenOut < seq.length) {
+ print( seq.substring(seqi, seqi+lenOut) );
+ seqi += lenOut;
+ } else {
+ var s = seq.substring(seqi);
+ seqi = lenOut - s.length;
+ print( s + seq.substring(0, seqi) );
+ }
+ n -= lenOut;
+ }
+}
+
+function fastaRandom(n, table) {
+ var line = new Array(60);
+ makeCumulative(table);
+ while (n>0) {
+ if (n<line.length) line = new Array(n);
+ for (var i=0; i<line.length; i++) {
+ var r = rand(1);
+ for (var c in table) {
+ if (r < table[c]) {
+ line[i] = c;
+ break;
+ }
+ }
+ }
+ print( line.join('') );
+ n -= line.length;
+ }
+}
+
+var n = arguments[0]
+
+print(">ONE Homo sapiens alu")
+fastaRepeat(2*n, ALU)
+
+print(">TWO IUB ambiguity codes")
+fastaRandom(3*n, IUB)
+
+print(">THREE Homo sapiens frequency")
+fastaRandom(5*n, HomoSap)
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/fibo.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/fibo.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,14 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by David Hedbor
+// modified by Isaac Gouy
+
+function fib(n) {
+ if (n < 2) return 1;
+ return fib(n-2) + fib(n-1);
+}
+
+var n = arguments[0];
+print(fib(n));
+
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/harmonic.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/harmonic.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,9 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by Isaac Gouy
+
+var n = arguments[0], partialSum = 0.0;
+for (var d = 1; d <= n; d++) partialSum += 1.0/d;
+print(partialSum.toFixed(9));
+
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/hash.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/hash.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,18 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by David Hedbor
+// modified by Isaac Gouy
+
+var i, c = 0;
+var n = arguments[0];
+
+var X = new Object();
+for (i=1; i<=n; i++) {
+ X[i.toString(16)] = i;
+}
+for (i=n; i>0; i--) {
+ if (X[i.toString()]) c++;
+}
+print(c);
+
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/hash2.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/hash2.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,28 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by David Hedbor
+// modified by Isaac Gouy
+
+var n = arguments[0];
+var hash1 = Object();
+var hash2 = Object();
+var arr = Array(10000);
+var idx;
+
+for (i=0; i<10000; i++) {
+ idx = "foo_"+i;
+ hash1[idx] = i;
+ // Do this here and run loop below one less since += on an undefined
+ // entry == NaN.
+ hash2[idx] = hash1[idx];
+}
+
+for (i = 1; i < n; i++) {
+ for(a in hash1) {
+ hash2[a] += hash1[a];
+ }
+}
+
+print(hash1["foo_1"], hash1["foo_9999"],
+ hash2["foo_1"], hash2["foo_9999"]);
Added: pypy/branch/js-refactoring/pypy/lang/js/bench/heapsort.javascript
==============================================================================
--- (empty file)
+++ pypy/branch/js-refactoring/pypy/lang/js/bench/heapsort.javascript Fri Apr 4 05:18:16 2008
@@ -0,0 +1,57 @@
+// The Great Computer Language Shootout
+// http://shootout.alioth.debian.org/
+//
+// contributed by David Hedbor
+// modified by Isaac Gouy
+
+var IM = 139968;
+var IA = 3877;
+var IC = 29573;
+
+var last = 42;
+
+function gen_random(max) { return(max * (last = (last * IA + IC) % IM) / IM); }
+
+function heapsort(n, ra) {
+ var l, j, ir, i;
+ var rra;
+
+ l = (n >> 1) + 1;
+ ir = n;
+ for (;;) {
+ if (l > 1) {
+ rra = ra[--l];
+ } else {
+ rra = ra[ir];
+ ra[ir] = ra[1];
+ if (--ir == 1) {
+ ra[1] = rra;
+ return;
+ }
+ }
+ i = l;
+ j = l << 1;
+ while (j <= ir) {
+ if (j < ir && ra[j] < ra[j+1]) { ++j; }
+ if (rra < ra[j]) {
+ ra[i] = ra[j];
+ j += (i = j);
+ } else {
+ j = ir + 1;
+ }
+ }
+ ra[i] = rra;
+ }
+}
+
+
+var n = arguments[0];
+var ary, i;
+
+// create an array of N random floats
+ary = Array(n+1);
+for (i=1; i<=n; i++) {
+ ary[i] = gen_random(1.0);
+}
+heapsort(n, ary);
+print(ary[n].toFixed(10));
More information about the pypy-svn
mailing list