The Computer Language
Benchmarks Game

binary-trees F# Mono LLVM #2 program

source code

// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// Minor modification by Don Syme & Jomo Fisher to use null as representation
// of Empty node.
// Based on F# version by Robert Pickering
// Based on ocaml version by Troestler Christophe & Isaac Gouy


[<CompilationRepresentation(CompilationRepresentationFlags
  .UseNullAsTrueValue)>]
type Tree<'T> = 
    | Empty 
    | Node of Tree<'T> * 'T * Tree<'T>

let rec make i d =
    if d = 0 then 
        Node(Empty, i, Empty)
    else
        let i2 = 2 * i
        let d = d - 1
        Node(make (i2 - 1) d, i, make i2 d)

let rec check x = 
    match x with 
    | Empty -> 0 
    | Node(l, i, r) -> i + check l - check r

let rec loopDepths maxDepth minDepth d =
    if d <= maxDepth then
        let niter = 1 <<< (maxDepth - d + minDepth)
        let mutable c = 0
        for i = 1 to niter do 
            c <- c + check (make i d) + check (make (-i) d)
        printf "%i\t trees of depth %i\t check: %i\n" (2 * niter) d c
        loopDepths maxDepth minDepth (d + 2)

[<EntryPoint>]
let main args =
    let minDepth = 4
    let maxDepth =
        let n = if args.Length > 0 then int args.[0] else 10
        max (minDepth + 2) n
    let stretchDepth = maxDepth + 1

    let c = check (make 0 stretchDepth)
    printf "stretch tree of depth %i\t check: %i\n" stretchDepth c
    let longLivedTree = make 0 maxDepth
    loopDepths maxDepth minDepth minDepth
    printf "long lived tree of depth %i\t check: %i\n" 
           maxDepth 
           (check longLivedTree)
    0

    

notes, command-line, and program output

NOTES:
32-bit Ubuntu one core
F# Compiler for F# 4.0 (Open Source Edition)
Mono JIT compiler version 4.5.1 (master/3e844dd Fri May  6 19:24:07 PDT 2016)
	LLVM:          yes(3.6.0svn-mono-master/9f79399)
	GC:            sgen



Sat, 07 May 2016 17:52:00 GMT

MAKE:
mv binarytrees.fsharp-2.fsharp binarytrees.fsharp-2.fs
/usr/local/bin/fsharpc --target:exe --platform:x86 -O  -o binarytrees.fsharp-2.fsharp_run.exe binarytrees.fsharp-2.fs
F# Compiler for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

/home/dunham/benchmarksgame_onecore/binarytrees/tmp/binarytrees.fsharp-2.fs(10,1): warning FS0221: The declarations in this file will be placed in an implicit module 'Binarytrees.fsharp-2' based on the file name 'binarytrees.fsharp-2.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file.
rm binarytrees.fsharp-2.fs
8.93s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/mono --llvm --gc=sgen binarytrees.fsharp-2.fsharp_run.exe 20

PROGRAM OUTPUT:
stretch tree of depth 21	 check: -1
2097152	 trees of depth 4	 check: -2097152
524288	 trees of depth 6	 check: -524288
131072	 trees of depth 8	 check: -131072
32768	 trees of depth 10	 check: -32768
8192	 trees of depth 12	 check: -8192
2048	 trees of depth 14	 check: -2048
512	 trees of depth 16	 check: -512
128	 trees of depth 18	 check: -128
32	 trees of depth 20	 check: -32
long lived tree of depth 20	 check: -1