-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_utils.go
More file actions
43 lines (35 loc) · 1.04 KB
/
benchmark_utils.go
File metadata and controls
43 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package api
import (
"io"
"net/http"
"testing"
"github.com/gin-gonic/gin"
)
// DummyResponseWriter implements http.ResponseWriter but discards all data
// This eliminates overhead from httptest.NewRecorder() in benchmarks
type DummyResponseWriter struct{}
func (d *DummyResponseWriter) Header() http.Header {
return http.Header{}
}
func (d *DummyResponseWriter) Write(data []byte) (int, error) {
// Discard all data - do nothing
return len(data), nil
}
func (d *DummyResponseWriter) WriteHeader(statusCode int) {
// Do nothing - discard status code
}
// setupBenchmarkRouter wraps the main setupRouter with benchmark mode configuration
func setupBenchmarkRouter() *gin.Engine {
// Set Gin to release mode for benchmarks
gin.SetMode(gin.ReleaseMode)
// Discard all output during benchmarks to only preserve benchmark output
gin.DefaultWriter = io.Discard
return setupRouter()
}
func benchmarkRequest(b *testing.B, req *http.Request) {
router := setupBenchmarkRouter()
w := new(DummyResponseWriter)
for b.Loop() {
router.ServeHTTP(w, req)
}
}