forked from jweir/csv
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench_test.go
More file actions
64 lines (51 loc) · 916 Bytes
/
bench_test.go
File metadata and controls
64 lines (51 loc) · 916 Bytes
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
55
56
57
58
59
60
61
62
63
64
package csv
import (
"bytes"
"compress/gzip"
"io/ioutil"
"os"
"testing"
)
// Benchmark with large CSV data set
func loadData() []byte {
f, err := os.Open("testdata/ercot-dam.csv.gz")
if err != nil {
panic(err)
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
panic(err)
}
data, err := ioutil.ReadAll(gz)
if err != nil {
panic(err)
}
return data
}
type Price struct {
DeliveryDate string
HourEnding string
BusName string
LMP float32
DSTFlag bool `true:"Y" false:"N"`
}
func BenchmarkUnmarshal(b *testing.B) {
b.StopTimer()
data := loadData()
b.StartTimer()
pp := []Price{}
err := Unmarshal(data, &pp)
if err != nil {
panic(err)
}
out, err := Marshal(pp)
if err != nil {
panic(err)
}
if bytes.Equal(data, out) != true {
panic("wrong results")
}
b.Logf("Unmarshal %d rows", len(pp))
b.Logf("Marshaled %d bytes", len(out))
}