-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.go
56 lines (44 loc) · 1.17 KB
/
main.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
package main
import (
"fmt"
"time"
"github.com/grd/stat"
)
const (
batchSize int = 10
replayCount = 200
)
func main() {
var e Engine
// batch latency measurements.
latencies := make([]time.Duration, replayCount*(len(ordersFeed)/batchSize))
for j := 0; j < replayCount; j++ {
e.Reset()
for i := batchSize; i < len(ordersFeed); i += batchSize {
begin := time.Now()
feed(&e, i-batchSize, i)
end := time.Now()
latencies[i/batchSize-1+(j*(len(ordersFeed)/batchSize))] = end.Sub(begin)
}
}
data := DurationSlice(latencies)
var mean float64 = stat.Mean(data)
var stdDev = stat.SdMean(data, mean)
var score = 0.5 * (mean + stdDev)
fmt.Printf("mean(latency) = %1.2f, sd(latency) = %1.2f\n", mean, stdDev)
fmt.Printf("You scored %1.2f. Try to minimize this.\n", score)
}
func feed(e *Engine, begin, end int) {
for i := begin; i < end; i++ {
var order Order = ordersFeed[i]
if order.price == 0 {
orderID := OrderID(order.size)
e.Cancel(orderID)
} else {
e.Limit(order)
}
}
}
type DurationSlice []time.Duration
func (f DurationSlice) Get(i int) float64 { return float64(f[i]) }
func (f DurationSlice) Len() int { return len(f) }