Skip to content

Instantly share code, notes, and snippets.

@vcastellm
Created October 3, 2011 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcastellm/1259375 to your computer and use it in GitHub Desktop.
Save vcastellm/1259375 to your computer and use it in GitHub Desktop.
Fibonacci Go
package main
import (
"http"
"fmt"
"log"
)
func fibonacci(n int) int {
result := 0
if (n < 2) {
result = 1
} else {
result = fibonacci(n - 2) + fibonacci(n - 1)
}
return result
}
func handler(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(fmt.Sprintf("%d", fibonacci(40))))
}
func main() {
http.HandleFunc("/", handler)
err := http.ListenAndServe(":12345", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
}
@vcastellm
Copy link
Author

$ time curl http://localhost:12345
165580141
real 0m1.963s
user 0m0.003s
sys 0m0.004s

@vcastellm
Copy link
Author

I'm getting 8s for nodejs

$ time curl http://localhost:1337/
165580141
real 0m7.952s
user 0m0.003s
sys 0m0.004s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment