/mobile Handheld Friendly website
Ubuntu : Intel® Q6600® one core |
Each table row shows performance measurements for this Go program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 12 | 0.21 | 0.22 | 260 | 516 | 0% 5% 0% 96% |
| 16 | 5.07 | 5.08 | 15,736 | 516 | 0% 1% 0% 100% |
| 20 | 108.70 | 108.81 | 259,996 | 516 | 0% 0% 0% 100% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read binary-trees benchmark to see what this program should do.
go version go1.1.1 linux/386
/* The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ * * contributed by The Go Authors. * based on C program by Kevin Carson * flag.Arg hack by Isaac Gouy */ package main import ( "flag" "fmt" "strconv" ) var n = 0 type Node struct { item int left, right *Node } func bottomUpTree(item, depth int) *Node { if depth <= 0 { return &Node{item: item} } return &Node{ item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1) } } func (n *Node) itemCheck() int { if n.left == nil { return n.item } return n.item + n.left.itemCheck() - n.right.itemCheck() } const minDepth = 4 func main() { flag.Parse() if flag.NArg() > 0 { n,_ = strconv.Atoi( flag.Arg(0) ) } maxDepth := n if minDepth + 2 > n { maxDepth = minDepth + 2 } stretchDepth := maxDepth + 1 check := bottomUpTree(0, stretchDepth).itemCheck() fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check) longLivedTree := bottomUpTree(0, maxDepth) for depth := minDepth; depth <= maxDepth; depth+=2 { iterations := 1 << uint(maxDepth - depth + minDepth) check = 0 for i := 1; i <= iterations; i++ { check += bottomUpTree(i,depth).itemCheck() check += bottomUpTree(-i,depth).itemCheck() } fmt.Printf("%d\t trees of depth %d\t check: %d\n", iterations*2, depth, check) } fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck()) }
Thu, 13 Jun 2013 20:10:23 GMT MAKE: /usr/local/src/go/bin/go build -o binarytrees.go_run 0.29s to complete and log all make actions COMMAND LINE: ./binarytrees.go_run 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