-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.go
163 lines (151 loc) · 4.82 KB
/
printer.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"fmt"
"strings"
"time"
)
type TablePrinter struct{}
func (p *TablePrinter) Print(r *TesterResults) {
var header = []string{"Test case", "ObjectId", "ULID", "UUID", "% diff ULID", "% diff UUID"}
var data = [][]string{
append([]string{"1M inserts batched, batch size = 1k"}, p.makeRowDataInsertBatches(r.InsertsBatched1M1K)...),
append([]string{"1M inserts batched, batch size = 5k"}, p.makeRowDataInsertBatches(r.InsertsBatched1M5K)...),
append([]string{"1M inserts batched, batch size = 10k"}, p.makeRowDataInsertBatches(r.InsertsBatched1M10K)...),
append([]string{"1M inserts"}, p.makeRowDataInserts(r.Insert1M)...),
append(
[]string{"10M inserts batched, 10M documents already present, batch size = 10k"},
p.makeRowDataInsertBatchesPresInsert(r.InsertsBatchedPres10M10K)...,
),
append(
[]string{"10M inserts batched, 10M documents already present, batch size = 100k"},
p.makeRowDataInsertBatchesPresInsert(r.InsertsBatchedPres10M10K)...,
),
append(
[]string{"Index size with 20M docs in bytes"},
p.makeRowDataInsertBatchesPresIdxSize(r.InsertsBatchedPres10M10K)...,
),
append(
[]string{"Get by ID from 20M docs, avg duration"},
p.makeRowDataInsertBatchesPresGetByID(r.InsertsBatchedPres10M10K)...,
),
}
p.printSep()
p.printHeader(header)
p.printSep()
p.printData(data)
p.printSep()
}
func (p *TablePrinter) printHeader(r []string) {
fmt.Println(
"|", fmt.Sprintf("%-70s", r[0]),
"|", fmt.Sprintf("%-10s", r[1]),
"|", fmt.Sprintf("%-12s", r[2]),
"|", fmt.Sprintf("%-12s", r[3]),
"|", fmt.Sprintf("%-12s", r[4]),
"|", fmt.Sprintf("%-12s", r[5]),
"|")
}
func (p *TablePrinter) printSep() {
fmt.Println(
"|", strings.Repeat("-", 70),
"|", strings.Repeat("-", 10),
"|", strings.Repeat("-", 12),
"|", strings.Repeat("-", 12),
"|", strings.Repeat("-", 12),
"|", strings.Repeat("-", 12),
"|")
}
func (p *TablePrinter) printData(data [][]string) {
for _, row := range data {
fmt.Println(
"|", fmt.Sprintf("%-70s", row[0]),
"|", fmt.Sprintf("%-10s", row[1]),
"|", fmt.Sprintf("%-12s", row[2]),
"|", fmt.Sprintf("%-12s", row[3]),
"|", fmt.Sprintf("%-12s", row[4]),
"|", fmt.Sprintf("%-12s", row[5]),
"|")
}
}
func (p *TablePrinter) makeRowDataInsertBatches(r *InsertBatchesTestResult) []string {
if r == nil {
return nil
}
return []string{
r.ObjectIDDuration.Round(1 * time.Millisecond).String(),
r.ULIDDuration.Round(1 * time.Millisecond).String(),
r.UUIDDuration.Round(1 * time.Millisecond).String(),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDDuration.Microseconds(),
r.ULIDDuration.Microseconds(),
)),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDDuration.Microseconds(),
r.UUIDDuration.Microseconds(),
)),
}
}
func (p *TablePrinter) makeRowDataInsertBatchesPresInsert(r *InsertBatchesWithPresentTestResult) []string {
if r == nil {
return nil
}
return []string{
r.ObjectIDInsertDuration.Round(1 * time.Millisecond).String(),
r.ULIDInsertDuration.Round(1 * time.Millisecond).String(),
r.UUIDInsertDuration.Round(1 * time.Millisecond).String(),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDInsertDuration.Microseconds(),
r.ULIDInsertDuration.Microseconds(),
)),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDInsertDuration.Microseconds(),
r.UUIDInsertDuration.Microseconds(),
)),
}
}
func (p *TablePrinter) makeRowDataInsertBatchesPresIdxSize(r *InsertBatchesWithPresentTestResult) []string {
if r == nil {
return nil
}
return []string{
byteCountIEC(r.ObjectIDIdxSize),
byteCountIEC(r.ULIDIdxSize),
byteCountIEC(r.UUIDIdxSize),
fmt.Sprintf("%.2f%%", calcDiffPercent(r.ObjectIDIdxSize, r.ULIDIdxSize)),
fmt.Sprintf("%.2f%%", calcDiffPercent(r.ObjectIDIdxSize, r.UUIDIdxSize)),
}
}
func (p *TablePrinter) makeRowDataInsertBatchesPresGetByID(r *InsertBatchesWithPresentTestResult) []string {
if r == nil {
return nil
}
return []string{
r.ObjectIDGetDuration.Round(1 * time.Microsecond).String(),
r.ULIDGetDuration.Round(1 * time.Microsecond).String(),
r.UUIDGetDuration.Round(1 * time.Microsecond).String(),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDGetDuration.Microseconds(), r.ULIDGetDuration.Microseconds(),
)),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDGetDuration.Microseconds(), r.UUIDGetDuration.Microseconds(),
)),
}
}
func (p *TablePrinter) makeRowDataInserts(r *InsertTestResult) []string {
if r == nil {
return nil
}
return []string{
r.ObjectIDDuration.Round(1 * time.Millisecond).String(),
r.ULIDDuration.Round(1 * time.Millisecond).String(),
r.UUIDDuration.Round(1 * time.Millisecond).String(),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDDuration.Microseconds(),
r.ULIDDuration.Microseconds(),
)),
fmt.Sprintf("%.2f%%", calcDiffPercent(
r.ObjectIDDuration.Microseconds(),
r.UUIDDuration.Microseconds(),
)),
}
}