-
Notifications
You must be signed in to change notification settings - Fork 8
/
Java.java
151 lines (121 loc) · 3.25 KB
/
Java.java
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
146
147
148
149
150
151
public class Java
{
private static final int NUM_RECORDS = 50 * 1000 * 444;
private static JavaMemoryTrade[] trades;
public static void main(final String[] args)
{
for (int i = 0; i < 5; i++)
{
System.gc();
perfRun(i);
}
}
private static void perfRun(final int runNum)
{
long start = System.currentTimeMillis();
init();
long buyCost = 0;
long sellCost = 0;
for (int i = 0; i < NUM_RECORDS; i++)
{
final JavaMemoryTrade trade = get(i);
if (trade.getSide() == 'B')
{
buyCost += (trade.getPrice() * trade.getQuantity());
}
else
{
sellCost += (trade.getPrice() * trade.getQuantity());
}
}
long duration = System.currentTimeMillis() - start;
System.out.println(runNum + " - duration " + duration + "ms");
System.out.println("buyCost = " + buyCost + " sellCost = " + sellCost);
}
private static JavaMemoryTrade get(final int index)
{
return trades[index];
}
public static void init()
{
trades = new JavaMemoryTrade[NUM_RECORDS];
for (int i = 0; i < NUM_RECORDS; i++)
{
JavaMemoryTrade trade = new JavaMemoryTrade();
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 static class JavaMemoryTrade
{
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(final long tradeId)
{
this.tradeId = tradeId;
}
public long getClientId()
{
return clientId;
}
public void setClientId(final long clientId)
{
this.clientId = clientId;
}
public int getVenueCode()
{
return venueCode;
}
public void setVenueCode(final int venueCode)
{
this.venueCode = venueCode;
}
public int getInstrumentCode()
{
return instrumentCode;
}
public void setInstrumentCode(final int instrumentCode)
{
this.instrumentCode = instrumentCode;
}
public long getPrice()
{
return price;
}
public void setPrice(final long price)
{
this.price = price;
}
public long getQuantity()
{
return quantity;
}
public void setQuantity(final long quantity)
{
this.quantity = quantity;
}
public char getSide()
{
return side;
}
public void setSide(final char side)
{
this.side = side;
}
}
}