Skip to content

Commit

Permalink
action for benchmarking detectors (#590)
Browse files Browse the repository at this point in the history
* add action for benchmarking each detector
  • Loading branch information
gabriel-vasile authored Oct 13, 2024
1 parent fd16da2 commit 458b62d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 76 deletions.
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.2.1
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

0 comments on commit 458b62d

Please sign in to comment.