Skip to content

Commit 9f5aca4

Browse files
committed
udpate test benchmark to add message bytes count
1 parent 6d208b0 commit 9f5aca4

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

rbc/fourrounds/rbc_benchmark_test.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/sha256"
77
"encoding/csv"
88
"errors"
9+
"fmt"
910
"os"
1011
"strconv"
1112
"student_25_adkg/networking"
@@ -105,21 +106,23 @@ func Benchmark_Threshold20(b *testing.B) {
105106
b.ReportAllocs()
106107
}
107108

108-
func BenchmarkRBC_TimingsMessages(b *testing.B) {
109-
b.Skip("Skipping this test by default. Run explicitly if needed.")
110-
minThreshold := 2
111-
maxThreshold := 30
109+
func TestRBC_TimingsMessages(b *testing.T) {
110+
//b.Skip("Skipping this test by default. Run explicitly if needed.")
111+
minThreshold := 5
112+
maxThreshold := 35
113+
114+
stepSize := 5
112115

113116
messageLength := 2
114117
message, messageHash := generateMessage(messageLength)
115118

116-
size := maxThreshold - minThreshold + 1
119+
size := (maxThreshold-minThreshold)/stepSize + 1
117120
thresholds := make([]int, size)
118121
durations := make([]time.Duration, size)
119-
messagesCounts := make([]int, size)
122+
messagesSent := make([][][]byte, size)
120123

121124
idx := 0
122-
for threshold := minThreshold; threshold <= maxThreshold; threshold++ {
125+
for threshold := minThreshold; threshold <= maxThreshold; threshold += stepSize {
123126
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
124127
network := networking.NewTransportNetwork(udp.NewUDP())
125128
nodes, err := createNetwork(network, threshold)
@@ -137,37 +140,47 @@ func BenchmarkRBC_TimingsMessages(b *testing.B) {
137140

138141
thresholds[idx] = threshold
139142
durations[idx] = end.Sub(start)
140-
messagesCounts[idx] = len(nodes[0].GetReceived())
143+
messagesSent[idx] = make([][]byte, 0)
144+
for _, node := range nodes {
145+
messagesSent[idx] = append(messagesSent[idx], node.GetReceived()...)
146+
}
141147
idx++
142148
}
143149

144-
saveToCSV(durations, thresholds, messagesCounts)
150+
saveToCSV(b, durations, thresholds, messagesSent)
145151
}
146152

147-
func saveToCSV(timings []time.Duration, thresholds, messagesCounts []int) {
153+
func saveToCSV(t require.TestingT, timings []time.Duration, thresholds []int, messages [][][]byte) {
154+
fmt.Println("Writing to CSV")
148155
// Open file for writing
149156
file, err := os.Create("output.csv")
150-
if err != nil {
151-
return
152-
}
157+
require.NoError(t, err)
153158
defer file.Close()
154159

155160
// Create CSV writer
156161
writer := csv.NewWriter(file)
157162
defer writer.Flush()
158163

159164
// Write header
160-
err = writer.Write([]string{"Timing(ms)", "Threshold", "MessageCount"})
165+
err = writer.Write([]string{"Timing(ms)", "Threshold", "MessageCount", "MessagesBytesCount"})
161166
if err != nil {
162167
panic(err)
163168
}
164169

165170
// Write data rows
166171
for i := 0; i < len(timings); i++ {
172+
173+
messagesCount := len(messages[i])
174+
bytesCount := int64(0)
175+
for _, m := range messages[i] {
176+
bytesCount += int64(len(m))
177+
}
178+
167179
row := []string{
168180
strconv.FormatInt(timings[i].Milliseconds(), 10),
169181
strconv.Itoa(thresholds[i]),
170-
strconv.Itoa(messagesCounts[i]),
182+
strconv.Itoa(messagesCount),
183+
strconv.FormatInt(bytesCount, 10),
171184
}
172185
if err := writer.Write(row); err != nil {
173186
continue

0 commit comments

Comments
 (0)