-
Notifications
You must be signed in to change notification settings - Fork 8
/
Go3.go
75 lines (62 loc) · 1.28 KB
/
Go3.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
package main
import (
"fmt"
"time"
"math/big"
)
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()
buyCost := big.NewInt(0)
sellCost := big.NewInt(0)
var i int64
for ; i < NUM_RECORDS; i++ {
trade := &(trades[i])
if (*trade).Side == 'B' {
buyCost = buyCost.Add( buyCost, big.NewInt( (*trade).Price * (*trade).Quantity ) )
} else {
sellCost = sellCost.Add( sellCost, big.NewInt( (*trade).Price * (*trade).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++ {
trade := &(trades[i])
(*trade).TradeId = i
(*trade).ClientId = 1
(*trade).VenueCode = 123
(*trade).InstrumentCode = 321
(*trade).Price = i
(*trade).Quantity = i
if (i&1) == 0 {
(*trade).Side = 'B'
} else {
(*trade).Side = 'S'
}
}
}