Skip to content

Commit

Permalink
Add basic Parser.Next based benchmark (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar authored Apr 2, 2023
1 parent ed68d94 commit f77ffde
Showing 1 changed file with 34 additions and 0 deletions.
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

0 comments on commit f77ffde

Please sign in to comment.