-
Notifications
You must be signed in to change notification settings - Fork 8
/
CS.cs
145 lines (116 loc) · 3.24 KB
/
CS.cs
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
using System;
public class MemtestS{
private const int NUM_RECORDS = 50 * 1000 * 444;
private static CSMemoryTrade[] trades;
static void Main(){
for (int i = 0; i < 5; i++){
GC.Collect();
perfRun(i);
}
}
private static void perfRun(int runNum){
long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long start = milliseconds;
init();
long buyCost = 0;
long sellCost = 0;
for (int i = 0; i < NUM_RECORDS; i++){
CSMemoryTrade trade = getATrade(i);
if (trade.getSide() == 'B'){
buyCost += (trade.getPrice() * trade.getQuantity());
}
else{
sellCost += (trade.getPrice() * trade.getQuantity());
}
}
milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long end = milliseconds;
long duration = end - start;
System.Console.Write(runNum + " - duration " + duration + "ms\n");
System.Console.Write("buyCost = " + buyCost + " sellCost = " + sellCost + "\n");
}
private static CSMemoryTrade getATrade(int index){
return trades[index];
}
public static void init()
{
trades = new CSMemoryTrade[NUM_RECORDS];
for (int i = 0; i < NUM_RECORDS; i++){
CSMemoryTrade trade = new CSMemoryTrade();
trades[i] = trade;
trade.setTradeId(i);
trade.setClientId(1);
trade.setVenueCode(123);
trade.setInstrumentCode(321);
trade.setPrice(i);
trade.setQuantity(i);
trade.setSide((i & 1) == 0 ? 'B' : 'S');
}
}
private sealed class CSMemoryTrade
{
private long tradeId;
private long clientId;
private int venueCode;
private int instrumentCode;
private long price;
private long quantity;
private char side;
public long getTradeId()
{
return tradeId;
}
public void setTradeId(long tradeId)
{
this.tradeId = tradeId;
}
public long getClientId()
{
return clientId;
}
public void setClientId(long clientId)
{
this.clientId = clientId;
}
public int getVenueCode()
{
return venueCode;
}
public void setVenueCode(int venueCode)
{
this.venueCode = venueCode;
}
public int getInstrumentCode()
{
return instrumentCode;
}
public void setInstrumentCode(int instrumentCode)
{
this.instrumentCode = instrumentCode;
}
public long getPrice()
{
return price;
}
public void setPrice(long price)
{
this.price = price;
}
public long getQuantity()
{
return quantity;
}
public void setQuantity(long quantity)
{
this.quantity = quantity;
}
public char getSide()
{
return side;
}
public void setSide(char side)
{
this.side = side;
}
}
}