summaryrefslogtreecommitdiff
path: root/sheet_test.go
diff options
context:
space:
mode:
authorTed <37789839+Theodoree@users.noreply.github.com>2020-11-03 17:48:37 +0800
committerGitHub <noreply@github.com>2020-11-03 17:48:37 +0800
commitfcca8a38389c7a7f99639dc142b9b10c827ac7ce (patch)
treeaa0e2f264153a793f1157c23959a9c140fa1bf67 /sheet_test.go
parent9d470bb38f992d9f0da2168b7a576f9e212b7a88 (diff)
optimize memory allocation (#722)
* optimize marshal * optimize mem alloc * add benchmark testing * add NewSheetWithRowNum testing * sync struct fields order * add BenchmarkNewSheetWithStreamWriter * delete NewSheetWithRowNum and benchmark test
Diffstat (limited to 'sheet_test.go')
-rw-r--r--sheet_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/sheet_test.go b/sheet_test.go
index 1a59b65..4626003 100644
--- a/sheet_test.go
+++ b/sheet_test.go
@@ -3,6 +3,7 @@ package excelize
import (
"fmt"
"path/filepath"
+ "strconv"
"strings"
"testing"
@@ -344,3 +345,36 @@ func TestSetSheetName(t *testing.T) {
f.SetSheetName("Sheet1", "Sheet1")
assert.Equal(t, "Sheet1", f.GetSheetName(0))
}
+
+func BenchmarkNewSheet(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ newSheetWithSet()
+ }
+ })
+}
+func newSheetWithSet() {
+ file := NewFile()
+ file.NewSheet("sheet1")
+ for i := 0; i < 1000; i++ {
+ file.SetCellInt("sheet1", "A"+strconv.Itoa(i+1), i)
+ }
+ file = nil
+}
+
+func BenchmarkFile_SaveAs(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ newSheetWithSave()
+ }
+
+ })
+}
+func newSheetWithSave() {
+ file := NewFile()
+ file.NewSheet("sheet1")
+ for i := 0; i < 1000; i++ {
+ file.SetCellInt("sheet1", "A"+strconv.Itoa(i+1), i)
+ }
+ file.Save()
+}