Skip to content

Commit ed06e31

Browse files
committed
Some stats computed at the end of a run
1 parent 77ed904 commit ed06e31

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

.github/workflows/go.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ jobs:
2525
- name: Check out code into the Go module directory
2626
uses: actions/checkout@v4
2727

28-
- name: Vet
29-
run: go vet ./...
30-
3128
- name: Build
32-
run: go build -v .
29+
run: make build
3330

3431
- name: Test
35-
run: go test -v -cover ./...
32+
run: make test

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fmt:
2+
go fmt ./...
3+
4+
vet:
5+
go vet ./...
6+
test:
7+
go test -v -cover ./...
8+
9+
build:
10+
go build -v .
11+
12+
client:
13+
@go build ./tools/client.go
14+
15+
.PHONY: client

tools/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ const (
2121

2222
func main() {
2323
numWorkers := flag.Int("workers", defaultNumWorkers, "Number of workers (concurrency) running in parallel")
24-
totalReqs := flag.Int("reqs", defaultTotalReqs, "Requests per worker")
24+
reqsPerWorker := flag.Int("reqs", defaultTotalReqs, "Requests per worker")
2525
flag.Parse()
2626

2727
var wg sync.WaitGroup
2828
wg.Add(*numWorkers)
2929
fmt.Printf("Running with concurrency=%v\n", *numWorkers)
30+
t0 := time.Now()
3031
for i := 0; i < *numWorkers; i++ {
31-
go worker(i, *totalReqs, &wg)
32+
go worker(i, *reqsPerWorker, &wg)
3233
}
3334

3435
wg.Wait()
36+
t1 := time.Since(t0)
3537
fmt.Println("All workers completed")
38+
totalReqs := (*numWorkers) * (*reqsPerWorker)
39+
// t1 is of type time.Duration which is int64 and represents nanoseconds
40+
rps := float32(totalReqs) / (float32(t1) / 1e9)
41+
fmt.Printf("Requests=%v, elapsed=%v, %v rps\n", totalReqs, t1, rps)
3642
}
3743

3844
func worker(id, numReqs int, wg *sync.WaitGroup) {

0 commit comments

Comments
 (0)