// Simple stupid Fibonacci microbenchmark. See dumbfib.S and concfib.go. // On my old laptop: // $ time ./fib 40 // 165580141 // // real 0m2.607s // user 0m2.596s // sys 0m0.008s // // That used to be (/ 2.607 .910) = 2.86 times slower than // GCC-compiled C. It amounts to (/ 165580141.0 2.607) = 64 million // leaf calls per second. // GCC has improved to the point where that’s no longer a useful // comparison. On this Celeron N4120 with argument 39 I get // 102334155, corresponding to 40 in dumbfib.S, in 824–826 // milliseconds, about 21% slower than dumbfib.S. package main import ( "fmt" "os" "strconv" ) func fib(n int) int { if n < 2 { return 1 } else { return fib(n-1) + fib(n-2) } } func main() { n, err := strconv.Atoi(os.Args[1]) if err != nil { panic("whoa") } fmt.Println(fib(n)) }