Add benchmark for adding images to sheet (#367)

* Add benchmark for adding images to sheet

This should help track performance regressions in future changes.

* Only transform sheet name if necessary
formula
Michael 6 years ago committed by xuri
parent 677a22d994
commit 2874d75555

3
.gitignore vendored

@ -1,2 +1,5 @@
~$*.xlsx
test/Test*.xlsx
*.out
test/image3.png
*.test

@ -0,0 +1,20 @@
package excelize
import (
"fmt"
_ "image/png"
"io/ioutil"
"testing"
)
func BenchmarkAddPictureFromBytes(b *testing.B) {
f := NewFile()
imgFile, err := ioutil.ReadFile("logo.png")
if err != nil {
panic("unable to load image for benchmark")
}
b.ResetTimer()
for i := 1; i <= b.N; i++ {
f.AddPictureFromBytes("Sheet1", fmt.Sprint("A", i), "", "logo", ".png", imgFile)
}
}

@ -778,7 +778,8 @@ func (f *File) UnprotectSheet(sheet string) {
// trimSheetName provides a function to trim invaild characters by given worksheet
// name.
func trimSheetName(name string) string {
var r []rune
if strings.ContainsAny(name, ":\\/?*[]") || utf8.RuneCountInString(name) > 31 {
r := make([]rune, 0, 31)
for _, v := range name {
switch v {
case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[]
@ -786,10 +787,11 @@ func trimSheetName(name string) string {
default:
r = append(r, v)
}
if len(r) == 31 {
break
}
}
name = string(r)
if utf8.RuneCountInString(name) > 31 {
name = string([]rune(name)[0:31])
}
return name
}

Loading…
Cancel
Save