Bug 449371 Firefox/Thunderbird crashes at exit [@ gdk_display_x11_finalize], p=Brian...
[wine-gecko.git] / testing / performance / talos / page_load_test / jss / real-fannkuch-2.html
blob77deb91fc593f151412f12acffaa8e3c2a24e8d0
1 <html><head>
2 <!-- MOZ_INSERT_CONTENT_HOOK -->
3 <script src = runner.js></script>
4 <script>
5 var onlyName = 'Pfannkuchen', onlyNum = 6;
6 function thisTest() {
8 /* The Great Computer Language Shootout
9 http://shootout.alioth.debian.org/
10 contributed by Isaac Gouy */
12 function fannkuch(n) {
13 var check = 0;
14 var perm = Array(n);
15 var perm1 = Array(n);
16 var count = Array(n);
17 var maxPerm = Array(n);
18 var maxFlipsCount = 0;
19 var m = n - 1;
21 for (var i = 0; i < n; i++) perm1[i] = i;
22 var r = n;
24 while (true) {
25 // write-out the first 30 permutations
26 if (check < 30){
27 var s = "";
28 for(var i=0; i<n; i++) s += (perm1[i]+1).toString();
29 check++;
32 while (r != 1) { count[r - 1] = r; r--; }
33 if (!(perm1[0] == 0 || perm1[m] == m)) {
34 for (var i = 0; i < n; i++) perm[i] = perm1[i];
36 var flipsCount = 0;
37 var k;
39 while (!((k = perm[0]) == 0)) {
40 var k2 = (k + 1) >> 1;
41 for (var i = 0; i < k2; i++) {
42 var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp;
44 flipsCount++;
47 if (flipsCount > maxFlipsCount) {
48 maxFlipsCount = flipsCount;
49 for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];
53 while (true) {
54 if (r == n) return maxFlipsCount;
55 var perm0 = perm1[0];
56 var i = 0;
57 while (i < r) {
58 var j = i + 1;
59 perm1[i] = perm1[j];
60 i = j;
62 perm1[r] = perm0;
64 count[r] = count[r] - 1;
65 if (count[r] > 0) break;
66 r++;
71 startTest("real-fannkuch");
73 var ret;
75 for ( var n = 5; n <= 8; n++ ) (function(n){
76 test( "Pfannkuchen", n, function(){
77 ret = fannkuch(n);
78 });
79 })(n);
81 endTest();
83 </script>
84 <body onload="thisTest()"></body></html>