Bug 449371 Firefox/Thunderbird crashes at exit [@ gdk_display_x11_finalize], p=Brian...
[wine-gecko.git] / testing / performance / talos / page_load_test / jss / real-binary-trees-3.html
blobf6380f9c3c79a460c811cf31969fdd927cd60516
1 <html><head>
2 <!-- MOZ_INSERT_CONTENT_HOOK -->
3 <script src = runner.js></script>
4 <script>
5 var onlyName = 'Binary Trees', onlyNum = 8;
6 function thisTest() {
8 /* The Great Computer Language Shootout
9 http://shootout.alioth.debian.org/
10 contributed by Isaac Gouy */
12 function TreeNode(left,right,item){
13 this.left = left;
14 this.right = right;
15 this.item = item;
18 TreeNode.prototype.itemCheck = function(){
19 if (this.left==null) return this.item;
20 else return this.item + this.left.itemCheck() - this.right.itemCheck();
23 function bottomUpTree(item,depth){
24 if (depth>0){
25 return new TreeNode(
26 bottomUpTree(2*item-1, depth-1)
27 ,bottomUpTree(2*item, depth-1)
28 ,item
31 else {
32 return new TreeNode(null,null,item);
36 startTest("real-binary-trees");
38 var ret;
40 for ( var n = 2; n <= 8; n *= 2 ) (function(n){
41 test( "Binary Trees", n, function(){
42 var minDepth = 4;
43 var maxDepth = Math.max(minDepth + 2, n);
44 var stretchDepth = maxDepth + 1;
46 var check = bottomUpTree(0,stretchDepth).itemCheck();
48 var longLivedTree = bottomUpTree(0,maxDepth);
49 for (var depth=minDepth; depth<=maxDepth; depth+=2){
50 var iterations = 1 << (maxDepth - depth + minDepth);
52 check = 0;
53 for (var i=1; i<=iterations; i++){
54 check += bottomUpTree(i,depth).itemCheck();
55 check += bottomUpTree(-i,depth).itemCheck();
59 ret = longLivedTree.itemCheck();
60 });
61 })(n);
63 endTest();
65 </script>
66 <body onload="thisTest()"></body></html>