-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench_test.nogo
54 lines (49 loc) · 1.13 KB
/
bench_test.nogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// file has a weird filename to avoid dragging in a go.mod dependency
package streamxlsx_test
import (
"bytes"
"log"
"os"
"runtime/pprof"
"strconv"
"testing"
"github.com/alicebob/streamxlsx"
"github.com/tealeg/xlsx/v2"
)
func BenchmarkStream(b *testing.B) {
if true {
f, err := os.Create("/tmp/stream.pprof")
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close() // error handling omitted for example
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
for i := 0; i < b.N; i++ {
buf := &bytes.Buffer{}
s := streamxlsx.New(buf)
for j := 0; j < 1_000_000; j++ {
s.WriteRow(j, s.Format("0.00", j), strconv.Itoa(j))
}
s.Close()
}
}
func BenchmarkTealeg(b *testing.B) {
for i := 0; i < b.N; i++ {
f := xlsx.NewFile()
sheet, _ := f.AddSheet("foo")
for j := 0; j < 1_000_000; j++ {
row := sheet.AddRow()
row.AddCell().SetInt(j)
cell := row.AddCell()
cell.SetInt(j)
cell.SetFormat("0.00")
row.AddCell().SetValue(strconv.Itoa(j))
}
buf := &bytes.Buffer{}
f.Write(buf)
}
}