mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 10:02:10 +08:00
And I test them benchmark: code: ```go package stringsbench import "strings" func index(part string) string { if index := strings.IndexByte(part, ';'); index >= 0 { if part := strings.TrimSpace(strings.Split(part, ";")[0]); part != "" { return part[0:index] } } return "" } func split(part string) string { return strings.Split(part, ";")[0] } ``` ```go package stringsbench import ( "testing" ) func BenchmarkIndex(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { index("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") } }) } func BenchmarkSplit(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { split("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") } }) } ``` And the result: ```shell ➜ strings go test --bench=. goos: darwin goarch: amd64 BenchmarkIndex-8 30000000 46.1 ns/op BenchmarkSplit-8 50000000 35.9 ns/op PASS ok _/Users/tianou/strings 3.271s ➜ strings go test --bench=. goos: darwin goarch: amd64 BenchmarkIndex-8 30000000 44.2 ns/op BenchmarkSplit-8 50000000 34.7 ns/op PASS ok _/Users/tianou/strings 3.156s ➜ strings go test --bench=. goos: darwin goarch: amd64 BenchmarkIndex-8 30000000 45.6 ns/op BenchmarkSplit-8 50000000 35.3 ns/op PASS ok _/Users/tianou/strings 3.230s ``` add grpc example (#1401) use grpc helloworld example.
14 lines
335 B
Bash
14 lines
335 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
echo "mode: count" > coverage.out
|
|
|
|
for d in $(go list ./... | grep -E 'gin$|binding$|render$' | grep -v 'examples'); do
|
|
go test -v -covermode=count -coverprofile=profile.out $d
|
|
if [ -f profile.out ]; then
|
|
cat profile.out | grep -v "mode:" >> coverage.out
|
|
rm profile.out
|
|
fi
|
|
done
|