The Q6600
Benchmarks Game

binary-trees Dart snapshot program

source code

/* The Computer Language Benchmarks game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

   contributed by Jos Hirth, transliterated from Jarkko Miettinen's Java program
   *reset*
*/

final int minDepth = 4;

void main(args){
  int n = args.length > 0 ? int.parse(args[0]) : 0;

  int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n;
  int stretchDepth = maxDepth + 1;

  int check = (TreeNode.bottomUpTree(stretchDepth)).itemCheck();
  print("stretch tree of depth $stretchDepth\t check: $check");

  TreeNode longLivedTree = TreeNode.bottomUpTree(maxDepth);

  for (int depth = minDepth; depth <= maxDepth; depth += 2){
    int iterations = 1 << (maxDepth - depth + minDepth);
    check = 0;

    for (int i = 1; i <= iterations; i++){
      check += (TreeNode.bottomUpTree(depth)).itemCheck();
    }
    print("${iterations}\t trees of depth $depth\t check: $check");
  }
  print("long lived tree of depth $maxDepth\t check: ${longLivedTree.itemCheck()}");
}


class TreeNode{
  TreeNode left, right;

  TreeNode([this.left, this.right]);

  static TreeNode bottomUpTree(int depth){
    if (depth > 0){
      return new TreeNode(
        bottomUpTree(depth - 1),
        bottomUpTree(depth - 1)
      );
    }
    return new TreeNode();
  }

  int itemCheck(){
    if (left == null){
      return 1;
    }
    return 1 + left.itemCheck() + right.itemCheck();
  }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Dart VM version: 2.8.1 (stable) (Unknown timestamp) on "linux_x64"
--snapshot-kind=app-jit


Thu, 07 May 2020 02:55:52 GMT

MAKE:
/usr/bin/dartanalyzer binarytrees.dartsnapshot
make: /usr/bin/dartanalyzer: Command not found
make: [/home/dunham/8000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:448: binarytrees.dartsnapshot_run] Error 127 (ignored)
/usr/bin/dart --snapshot=binarytrees.snapshot --snapshot-kind=app-jit binarytrees.dartsnapshot 10
stretch tree of depth 11	 check: 4095
1024	 trees of depth 4	 check: 31744
256	 trees of depth 6	 check: 32512
64	 trees of depth 8	 check: 32704
16	 trees of depth 10	 check: 32752
long lived tree of depth 10	 check: 2047

3.56s to complete and log all make actions

COMMAND LINE:
/usr/bin/dart  binarytrees.snapshot 21

PROGRAM OUTPUT:
stretch tree of depth 22	 check: 8388607
2097152	 trees of depth 4	 check: 65011712
524288	 trees of depth 6	 check: 66584576
131072	 trees of depth 8	 check: 66977792
32768	 trees of depth 10	 check: 67076096
8192	 trees of depth 12	 check: 67100672
2048	 trees of depth 14	 check: 67106816
512	 trees of depth 16	 check: 67108352
128	 trees of depth 18	 check: 67108736
32	 trees of depth 20	 check: 67108832
long lived tree of depth 21	 check: 4194303