Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equalent go benchmark #12

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions benchmarks/golang/micro.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
package main

import (
"io"
"net/http"
)
import "net/http"

func hello(response http.ResponseWriter, request *http.Request) {
header := response.Header()
header["Date"] = nil
var (
helloResp = []byte("Hello world!")
notFoundResp = []byte("Not Found")
)

var text string
var status int
if request.URL.Path == "/" {
status = 200
text = "Hello world!"
} else {
status = 404
text = "Not Found"
}
response.WriteHeader(status)
io.WriteString(response, text)
func hello(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
w.WriteHeader(http.StatusNotFound)
w.Write(notFoundResp)
return
}
w.Write(helloResp)
}

func main() {
http.HandleFunc("/", hello)
http.ListenAndServe("0.0.0.0:8080", nil)
http.HandleFunc("/", hello)
http.ListenAndServe("0.0.0.0:8080", nil)
}