diff --git a/parse_test.go b/parse_test.go index 59657565..7b64533f 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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)