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

Benchmark across Parse options, add memory benchmarking. #264

Merged
merged 2 commits into from
Feb 26, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/bench_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
go install golang.org/x/perf/cmd/benchstat@latest
echo "New Commit:"
git log -1 --format="%H"
go test -bench=. -benchtime=.75s -count=8 > $HOME/new.txt
go test -bench=. -benchmem -benchtime=10x -count=7 > $HOME/new.txt
git reset --hard HEAD
git checkout $GITHUB_BASE_REF
echo "Base Commit:"
git log -1 --format="%H"
go test -bench=. -benchtime=.75s -count=8 > $HOME/old.txt
go test -bench=. -benchmem -benchtime=10x -count=7 > $HOME/old.txt
$GOBIN/benchstat $HOME/old.txt $HOME/new.txt

4 changes: 2 additions & 2 deletions .github/workflows/bench_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
go install golang.org/x/perf/cmd/benchstat@latest
echo "New Commit:"
git log -1 --format="%H"
go test -bench=. -benchtime=.75s -count=8 > $HOME/new.txt
go test -bench=. -benchmem -benchtime=10x -count=7 > $HOME/new.txt
git reset --hard HEAD
git checkout HEAD~1
echo "Base Commit:"
git log -1 --format="%H"
go test -bench=. -benchtime=.75s -count=8 > $HOME/old.txt
go test -bench=. -benchmem -benchtime=10x -count=7 > $HOME/old.txt
$GOBIN/benchstat $HOME/old.txt $HOME/new.txt
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ release:
tar -zcvf ${BINARY}-darwin-amd64.tar.gz ${BINARY}-darwin-amd64; \
zip -r ${BINARY}-windows-amd64.exe.zip ${BINARY}-windows-amd64.exe;

.PHONY: bench
bench:
go test -bench . -benchmem -benchtime=10x

bench-diff:
go test -bench . -benchtime=50x -count 5 > bench_current.txt
go test -bench . -benchmem -benchtime=10x -count 5 > bench_current.txt
git checkout main
go test -bench . -benchtime=50x -count 5 > bench_main.txt
go test -bench . -benchmem -benchtime=10x -count 5 > bench_main.txt
benchstat bench_main.txt bench_current.txt
git checkout -
63 changes: 43 additions & 20 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,53 @@ func TestParseFile_SkipProcessingPixelDataValue(t *testing.T) {

// BenchmarkParse runs sanity benchmarks over the sample files in testdata.
func BenchmarkParse(b *testing.B) {
files, err := ioutil.ReadDir("./testdata")
if err != nil {
b.Fatalf("unable to read testdata/: %v", err)
cases := []struct {
name string
opts []dicom.ParseOption
}{
{
name: "NoOptions",
},
{
name: "SkipPixelData",
opts: []dicom.ParseOption{dicom.SkipPixelData()},
},
{
name: "SkipProcessingPixelDataValue",
opts: []dicom.ParseOption{dicom.SkipProcessingPixelDataValue()},
},
}
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".dcm") {
b.Run(f.Name(), func(b *testing.B) {
dcm, err := os.Open("./testdata/" + f.Name())
if err != nil {
b.Errorf("Unable to open %s. Error: %v", f.Name(), err)
}
defer dcm.Close()
for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
files, err := ioutil.ReadDir("./testdata")
if err != nil {
b.Fatalf("unable to read testdata/: %v", err)
}
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".dcm") {
b.Run(f.Name(), func(b *testing.B) {

data, err := ioutil.ReadAll(dcm)
if err != nil {
b.Errorf("Unable to read file into memory for benchmark: %v", err)
}
dcm, err := os.Open("./testdata/" + f.Name())
if err != nil {
b.Errorf("Unable to open %s. Error: %v", f.Name(), err)
}
defer dcm.Close()

data, err := ioutil.ReadAll(dcm)
if err != nil {
b.Errorf("Unable to read file into memory for benchmark: %v", err)
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
_, _ = dicom.Parse(bytes.NewBuffer(data), int64(len(data)), nil, tc.opts...)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = dicom.Parse(bytes.NewBuffer(data), int64(len(data)), nil)
})
}
})
}
}
})
}
}

Expand Down