Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Few things to benchmark
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
var (
test_string = "This is just a test string."
)
func format_string(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, test_string)
}
func faux_cache() func(http.ResponseWriter, *http.Request) {
reader := strings.NewReader(test_string)
return func(w http.ResponseWriter, r *http.Request) {
io.Copy(w, reader)
}
}
func from_disk() func(http.ResponseWriter, *http.Request) {
fh, err := os.Create("temp_test_file")
if err != nil {
panic(err)
}
defer fh.Close()
fmt.Fprintf(fh, test_string)
return func(w http.ResponseWriter, r *http.Request) {
fh, err := os.Open("temp_test_file")
if err != nil {
panic(err)
}
defer fh.Close()
io.Copy(w, fh)
}
}
func main() {
http.HandleFunc("/1", format_string)
http.HandleFunc("/2", faux_cache())
http.HandleFunc("/3", from_disk())
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.