Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action for benchmarking detectors #590

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions .github/workflows/benchmark.go

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run benchmarks
on:
pull_request:
branches: [master]

permissions:
contents: read

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
# Base for comparison is master branch.
- name: Checkout code
uses: actions/checkout@v4.1.7
with:
ref: master
- name: Install Go
uses: actions/setup-go@v5.0.2
with:
go-version-file: 'go.mod'

# 30 runs with 100ms benchtime seems to result in acceptable p-values
# When I tried with count=10, it would be unreliable because of the actions
# runner is in a shared environment and CPU and mem would be affected by others. (or so I think)
- run: go test -run=none -bench=. -count=30 -benchtime=100ms -timeout=20m > /tmp/prev
- name: Checkout code
uses: actions/checkout@v4.1.7
- run: go test -run=none -bench=. -count=30 -benchtime=100ms -timeout=20m > /tmp/curr

- run: go install golang.org/x/perf/cmd/benchstat@latest
- run: benchstat /tmp/prev /tmp/curr
5 changes: 1 addition & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ jobs:
version: "v1.58"

test:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
Expand Down
33 changes: 1 addition & 32 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var testcases = []testcase{
{"utf16lebom.txt", text, "text/plain; charset=utf-16le", false},
{"utf32bebom.txt", text, "text/plain; charset=utf-32be", false},
{"utf32lebom.txt", text, "text/plain; charset=utf-32le", false},
{"utf8.txt", text, "text/plain; charset=utf-8", false},
{"utf8.txt", text, "text/plain; charset=utf-8", true},
{"utf8ctrlchars", root, "application/octet-stream", false},
{"vcf.vcf", vCard, "text/vcard", true},
{"vcf.dos.vcf", vCard, "text/vcard", false},
Expand Down Expand Up @@ -505,37 +505,6 @@ func BenchmarkAll(b *testing.B) {
}
}

func BenchmarkCommon(b *testing.B) {
commonFiles := []string{
"xlsx.xlsx",
"pptx.pptx",
"docx.docx",
"tar.tar",
"zip.zip",
"pdf.pdf",
"jpg.jpg",
"png.png",
"gif.gif",
"xls.xls",
"webm.webm",
"csv.csv",
"mp4.mp4",
}
for _, file := range commonFiles {
f, err := os.ReadFile(filepath.Join(testDataDir, file))
if err != nil {
b.Fatal(err)
}
b.Run(filepath.Ext(file), func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Detect(f)
}
})
}
}

// Check there are no panics for nil inputs.
func TestIndexOutOfRangePanic(t *testing.T) {
for _, n := range root.flatten() {
Expand Down