-
Notifications
You must be signed in to change notification settings - Fork 8
/
Go2.go
70 lines (59 loc) · 1.14 KB
/
Go2.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
package main
import (
"fmt"
"time"
)
const (
NUM_RECORDS = 50 * 1000 * 444
)
var (
trades [NUM_RECORDS]GoMemoryTrade
)
type GoMemoryTrade struct {
TradeId int64
ClientId int64
VenueCode int32
InstrumentCode int32
Price int64
Quantity int64
Side byte
}
func main() {
for i := 0; i < 5; i++ {
perfRun(i)
}
}
func perfRun(runNum int) {
start := time.Now()
initTrades()
var buyCost int64
var sellCost int64
var i int64
for ; i < NUM_RECORDS; i++ {
if trades[i].Side == 'B' {
buyCost += trades[i].Price * trades[i].Quantity
} else {
sellCost += trades[i].Price * trades[i].Quantity
}
}
endT := time.Now()
duration := endT.Sub(start).Nanoseconds() / 1000000
fmt.Printf("%v - duration %v ms\n", runNum, duration)
fmt.Printf("buyCost = %v sellCost = %v\n", buyCost, sellCost)
}
func initTrades() {
var i int64
for ; i < NUM_RECORDS; i++ {
trades[i].TradeId = i
trades[i].ClientId = 1
trades[i].VenueCode = 123
trades[i].InstrumentCode = 321
trades[i].Price = i
trades[i].Quantity = i
if (i&1) == 0 {
trades[i].Side = 'B'
} else {
trades[i].Side = 'S'
}
}
}