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

Add basic Parser.Next based benchmark #266

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
34 changes: 34 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,40 @@ func BenchmarkParse(b *testing.B) {
}
}

func BenchmarkParser_NextAPI(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) {

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++ {
r := bytes.NewReader(data)
p, _ := dicom.NewParser(r, int64(len(data)), nil)
var err error
for err == nil {
_, err = p.Next()
}
}
})
}
}
}

func Example_readFile() {
// See also: dicom.Parse, which uses a more generic io.Reader API.
dataset, _ := dicom.ParseFile("testdata/1.dcm", nil)
Expand Down