Added benchmark test

This commit is contained in:
2025-09-08 19:09:04 +01:00
parent 99a66976cd
commit b2bca295e0
3 changed files with 22 additions and 3 deletions
+3
View File
@@ -2,3 +2,6 @@ test:
go test -coverprofile=coverage.out ./... go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html go tool cover -html=coverage.out -o coverage.html
rm coverage.out rm coverage.out
bench:
go test -bench=. -cpuprofile=cpu.out -memprofile=mem.out
+18 -2
View File
@@ -5,8 +5,8 @@ import (
"testing" "testing"
) )
func TestFatQRAPI(t *testing.T) { var (
input := "A:123456789*B:999999990*C:PT*D:FT*E:N*F:20191231*" + completeInput = "A:123456789*B:999999990*C:PT*D:FT*E:N*F:20191231*" +
"G:FT AB2019/0035*H:CSDF7T5H-0035*I1:PT*I2:12000.00*I3:15000.00*" + "G:FT AB2019/0035*H:CSDF7T5H-0035*I1:PT*I2:12000.00*I3:15000.00*" +
"I4:900.00*I5:50000.00*I6:6500.00*I7:80000.00*I8:18400.00*J1:PT-AC*" + "I4:900.00*I5:50000.00*I6:6500.00*I7:80000.00*I8:18400.00*J1:PT-AC*" +
"J2:10000.00*J3:25000.56*J4:1000.02*J5:75000.00*J6:6750.00*" + "J2:10000.00*J3:25000.56*J4:1000.02*J5:75000.00*J6:6750.00*" +
@@ -14,6 +14,10 @@ func TestFatQRAPI(t *testing.T) {
"K5:25000.00*K6:3000.00*K7:40000.00*K8:8800.00*L:100.00*M:25.00*" + "K5:25000.00*K6:3000.00*K7:40000.00*K8:8800.00*L:100.00*M:25.00*" +
"N:64000.02*O:513600.58*P:100.00*Q:kLp0*R:9999*" + "N:64000.02*O:513600.58*P:100.00*Q:kLp0*R:9999*" +
"S:TB;PT00000000000000000000000;513500.58" "S:TB;PT00000000000000000000000;513500.58"
)
func TestFatQRAPI(t *testing.T) {
input := completeInput
var qr gofatqr.FatQR var qr gofatqr.FatQR
err := qr.Scan(input, 0) err := qr.Scan(input, 0)
@@ -21,3 +25,15 @@ func TestFatQRAPI(t *testing.T) {
t.Errorf("Should not have occurred an error for: %s, %+v", input, err) t.Errorf("Should not have occurred an error for: %s, %+v", input, err)
} }
} }
func BenchmarkFatQRScan(b *testing.B) {
b.ReportAllocs()
for b.Loop() {
var qr gofatqr.FatQR
err := qr.Scan(completeInput, 0)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
+1 -1
View File
@@ -627,7 +627,7 @@ func (fq *FatQR) scanPart(part []string) error {
func (fq *FatQR) scanParts(parts []string) error { func (fq *FatQR) scanParts(parts []string) error {
for k := range parts { for k := range parts {
keyValuePair := strings.Split(parts[k], ":") keyValuePair := strings.SplitN(parts[k], ":", 2)
if len(keyValuePair) != 2 { if len(keyValuePair) != 2 {
return fmt.Errorf("failed to parse key value pair: %s", parts[k]) return fmt.Errorf("failed to parse key value pair: %s", parts[k])
} }