The Computer Language
Benchmarks Game

binary-trees F# .NET Core #5 program

source code

(* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by Jack Mott
*)

open System
open System.Diagnostics

[<AllowNullLiteral>]
type TreeNode(left:TreeNode,right:TreeNode) = 
    member __.CheckSum =
        match right with 
        | null -> 1 
        | _ -> 1 + left.CheckSum + right.CheckSum

let rec mkTree(depth) =
    if depth = 0 then TreeNode(null, null)
    else TreeNode(mkTree (depth-1), mkTree(depth-1))

let bottomUpTree (depth) = mkTree(depth)

let minDepth = 4
[<EntryPoint>]
let main argv =     
    let n = if argv.Length > 0 then Int32.Parse(argv.[0]) else 0
    let maxDepth = Math.Max(minDepth + 2, n)
    let stretchDepth = maxDepth + 1
    let mutable check = bottomUpTree(stretchDepth).CheckSum
    Console.WriteLine("stretch tree of depth {0}\t check: {1}", stretchDepth, check)
    let longLivedTree = bottomUpTree(maxDepth)
    let mutable depth = minDepth
    while depth < maxDepth do    
         let iterations = 1 <<< ( maxDepth - depth + minDepth )
         check <- 0
         for i in 1 .. iterations do 
            check <- check + bottomUpTree(depth).CheckSum
         Console.WriteLine("{0}\t trees of depth {1}\t check: {2}",iterations, depth, check)
         depth <- depth + 2
    Console.WriteLine("long lived tree of depth {0}\t check: {1}",maxDepth, longLivedTree.CheckSum)        
    0
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
F# 4.1.0
dotnet 1.0.1 005db40cd1
"System.GC.Server": true


Sun, 16 Apr 2017 18:22:25 GMT

MAKE:
cp binarytrees.fsharpcore-5.fsharpcore Program.fs
cp Include/fsharpcore/tmp.fsproj .
cp Include/fsharpcore/runtimeconfig.template.json .
mkdir obj
cp Include/fsharpcore/project.assets.json ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.props ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.targets ./obj
/usr/bin/dotnet build -c Release
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

  tmp -> /home/dunham/benchmarksgame_quadcore/binarytrees/tmp/bin/Release/netcoreapp1.1/tmp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:11.63
12.10s to complete and log all make actions

COMMAND LINE:
/usr/bin/dotnet ./bin/Release/netcoreapp1.1/tmp.dll 14

UNEXPECTED OUTPUT 

6a7
> 16	 trees of depth 14	 check: 524272

PROGRAM OUTPUT:
stretch tree of depth 15	 check: 65535
16384	 trees of depth 4	 check: 507904
4096	 trees of depth 6	 check: 520192
1024	 trees of depth 8	 check: 523264
256	 trees of depth 10	 check: 524032
64	 trees of depth 12	 check: 524224
long lived tree of depth 14	 check: 32767