Created
October 3, 2011 15:30
-
-
Save vcastellm/1259375 to your computer and use it in GitHub Desktop.
Fibonacci Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"log" | |
) | |
func fibonacci(n int) int { | |
var result int | |
if n < 2 { | |
result = 1 | |
} else { | |
result = fibonacci(n-2) + fibonacci(n-1) | |
} | |
return result | |
} | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | |
w.Write([]byte(fmt.Sprintf("%d", fibonacci(40)))) | |
}) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting 8s for nodejs
$ time curl http://localhost:1337/
165580141
real 0m7.952s
user 0m0.003s
sys 0m0.004s