Skip to content

Commit

Permalink
Use binary
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Sep 23, 2023
1 parent 57879d3 commit 2201d9c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage.out
custom_metrics_benchmark.json
testdata/testbin/testbin
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ benchmark: depsdev
go test -modfile=testdata/go_test.mod -bench . -benchmem -benchtime 10000x -run Benchmark | octocov-go-test-bench --tee > custom_metrics_benchmark.json

cachegrind: depsdev
go mod tidy -modfile=testdata/go_test.mod
valgrind --tool=cachegrind --I1=8192,8,64 --D1=16384,4,64 --LL=32768,8,64 go test -modfile=testdata/go_test.mod -bench . -benchmem -benchtime 10000x -run Benchmark
cd testdata/testbin && go build -o testbin
valgrind --tool=cachegrind --I1=8192,8,64 --D1=16384,4,64 --LL=32768,8,64 ./testdata/testbin/testbin 10000
valgrind --tool=cachegrind --I1=8192,8,64 --D1=16384,4,64 --LL=32768,8,64 ./testdata/testbin/testbin 10000
valgrind --tool=cachegrind --I1=8192,8,64 --D1=16384,4,64 --LL=32768,8,64 ./testdata/testbin/testbin 10000

lint:
go mod tidy
Expand Down
13 changes: 13 additions & 0 deletions testdata/testbin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/k1LoW/rl/testdata/testbin

go 1.21.1

require (
github.com/go-chi/httprate v0.7.4
github.com/k1LoW/rl v0.6.1
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
golang.org/x/sync v0.3.0 // indirect
)
8 changes: 8 additions & 0 deletions testdata/testbin/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/go-chi/httprate v0.7.4 h1:a2GIjv8he9LRf3712zxxnRdckQCm7I8y8yQhkJ84V6M=
github.com/go-chi/httprate v0.7.4/go.mod h1:6GOYBSwnpra4CQfAKXu8sQZg+nZ0M1g9QnyFvxrAB8A=
github.com/k1LoW/rl v0.6.1 h1:97cFVVOMm3iXK9UdHxO78wO6FCmh4IA8edOoly64R8o=
github.com/k1LoW/rl v0.6.1/go.mod h1:FwcYhUX7i153XHIyR4OuOgR2a2KIzcBxrfanE9/O0S4=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
45 changes: 45 additions & 0 deletions testdata/testbin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"log"
"net/http"
"net/http/httptest"
"os"
"strconv"

"github.com/go-chi/httprate"
"github.com/k1LoW/rl"
"github.com/k1LoW/rl/testutil"
)

func main() {
n, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatal(err)
}
r := http.NewServeMux()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello, world"))
})
m := rl.New(
testutil.NewLimiter(10, httprate.KeyByIP, 0),
testutil.NewLimiter(10, testutil.KeyByHost, 0),
)
ts := httptest.NewServer(m(r))
defer ts.Close()

log.Printf("start %d requests", n)
for i := 0; i < n; i++ {
req, err := http.NewRequest("GET", ts.URL, nil)
if err != nil {
log.Fatal(err)
}
req.Host = "a.example.com"
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
}
log.Println("done")
}

0 comments on commit 2201d9c

Please sign in to comment.