From affd3469ba3ae457e006143523dc3ad8610b3dcb Mon Sep 17 00:00:00 2001 From: Larry Lv Date: Sun, 26 Jul 2020 18:33:50 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20benchmark=20for=20Fresh=20?= =?UTF-8?q?with=20stale=20etag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ctx_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ctx_test.go b/ctx_test.go index aad425b8..94874a02 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -632,6 +632,23 @@ func Test_Ctx_FormValue(t *testing.T) { utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") } +// go test -v -run=^$ -bench=Benchmark_Ctx_Fresh_StaleEtag -benchmem -count=4 +func Benchmark_Ctx_Fresh_StaleEtag(b *testing.B) { + app := New() + ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) + + for n := 0; n < b.N; n++ { + ctx.Fasthttp.Request.Header.Set(HeaderIfNoneMatch, "a, b, c, d") + ctx.Fasthttp.Request.Header.Set(HeaderCacheControl, "c") + ctx.Fresh() + + ctx.Fasthttp.Request.Header.Set(HeaderIfNoneMatch, "a, b, c, d") + ctx.Fasthttp.Request.Header.Set(HeaderCacheControl, "e") + ctx.Fresh() + } +} + // go test -run Test_Ctx_Fresh func Test_Ctx_Fresh(t *testing.T) { t.Parallel()