-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmark_test.go
103 lines (95 loc) · 1.86 KB
/
benchmark_test.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import "testing"
const (
numRows = 65536
numCols = 1
)
func BenchmarkRowBasedInterface(b *testing.B) {
scan := &tableReader{rows: makeInput(numRows, numCols, Int{})}
render := mulOperator{
input: scan,
fn: mulIntDatums,
arg: Int{2},
columnsToMultiply: []int{0},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for {
row := render.next()
if row == nil {
break
}
}
scan.reset()
}
}
func BenchmarkRowBasedTyped(b *testing.B) {
scan := &typedTableReader{rows: makeTypedInput(numRows, numCols, Int64Type)}
render := mulInt64Operator{
input: scan,
arg: 2,
columnsToMultiply: []int{0},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for {
row := render.next()
if row == nil {
break
}
}
scan.reset()
}
}
func BenchmarkRowBasedTypedBatch(b *testing.B) {
scan := &typedBatchTableReader{rows: makeTypedBatchInput(numRows, numCols, Int64Type)}
render := mulInt64BatchOperator{
input: scan,
arg: 2,
columnsToMultiply: []int{0},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for {
row := render.next()
if row == nil {
break
}
}
scan.reset()
}
}
func BenchmarkColBasedTyped(b *testing.B) {
scan := makeTypedColInput(numRows, numCols, Int64Type)
render := mulInt64ColOperator{
input: &scan,
arg: 2,
columnsToMultiply: []int{0},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for {
row := render.next()
if row.size == 0 {
break
}
}
scan.reset()
}
}
func mulInt(a, b Int) Int {
return Int{int64: a.int64 * b.int64}
}
func BenchmarkSpeedOfLight(b *testing.B) {
rows := make([]Int, numRows)
for i := range rows {
rows[i].int64 = int64(i)
}
arg := Int{int64: 2}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := range rows {
_ = mulInt(rows[j], arg)
}
}
}