From a27fa789755a53ea7199acc6dd64392b67940550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=92=D0=BE=D0=BB=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= Date: Fri, 25 Nov 2022 18:25:35 +0300 Subject: [PATCH] #1402 Get CountRows from sheet add close file and benchmark --- rows_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rows_test.go b/rows_test.go index bcfd253ef8..3a49c9c51e 100644 --- a/rows_test.go +++ b/rows_test.go @@ -1156,6 +1156,7 @@ func TestFile_CountRows(t *testing.T) { t.Run(tt.name, func(t *testing.T) { f, err := OpenFile(tt.fields.filename) assert.NoError(t, err) + defer f.Close() firstSheet := f.GetSheetName(0) got, err := f.CountRows(firstSheet) if !tt.wantErr(t, err, "CountRows") { @@ -1165,3 +1166,28 @@ func TestFile_CountRows(t *testing.T) { }) } } + +func BenchmarkFile_GetRows_Old(b *testing.B) { + for i := 0; i < b.N; i++ { + f, _ := OpenFile(filepath.Join("test", "Book1.xlsx")) + defer f.Close() + + firstSheet := f.GetSheetName(0) + count := 0 + rows, _ := f.GetRows(firstSheet) + for range rows { + count++ + } + } +} + +func BenchmarkFile_GetRows_New(b *testing.B) { + for i := 0; i < b.N; i++ { + f, _ := OpenFile(filepath.Join("test", "Book1.xlsx")) + defer f.Close() + + firstSheet := f.GetSheetName(0) + _, err := f.CountRows(firstSheet) + assert.NoError(b, err) + } +}