Created
October 28, 2022 20:48
-
-
Save costela/44079c1c742007d355cb3e382d0ac0ef to your computer and use it in GitHub Desktop.
Benchmark for golang/go#56480
This file contains 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
func BenchmarkServeContent(b *testing.B) { | |
type readSeekWriterTo interface { | |
io.ReadSeeker | |
io.WriterTo | |
} | |
content, err := os.ReadFile("../../testdata/Isaac.Newton-Opticks.txt") | |
if err != nil { | |
b.Fatalf("could not open source file: %v", err) | |
} | |
in := struct{ readSeekWriterTo }{bytes.NewReader(content)} | |
req := httptest.NewRequest(MethodGet, "/", NoBody) | |
// req.Header.Set("Range", "bytes=0-100000") | |
rw := httptest.NewRecorder() | |
rw.Header().Set("Content-Type", "text/plain") | |
b.ReportAllocs() | |
b.ResetTimer() | |
for i := 0; i <= b.N; i++ { | |
in.Seek(0, io.SeekStart) | |
ServeContent(rw, req, "foo.txt", time.Time{}, in) | |
b.SetBytes(rw.Result().ContentLength) | |
rw.Body.Reset() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment