forked from logicchains/ArrayAccessBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pypy.py
43 lines (38 loc) · 1.16 KB
/
Pypy.py
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
import time
NUM_RECORDS = 50* 1000 * 444
class PyMemTrade():
def __init__(self, tradeId, clientId, venueId, instrumentCode, price, quantity, side):
self.tradeId = tradeId
self.clientId = clientId
self.venueId = venueId
self.instrumentCode = instrumentCode
self.price = price
self.quantity = quantity
self.side = side
def initTrades(trades):
for i in xrange(0, NUM_RECORDS):
aside = ''
if (i % 2 == 0):
aside = 'B'
else:
aside = 'S'
trades[i] = PyMemTrade(i,1,123,321,i,i,aside)
def perfRun(runNum, trades):
start = time.time() * 1000
initTrades(trades)
buyCost = 0
sellCost = 0
for i in xrange(0, NUM_RECORDS):
trade = trades[i]
if (trade.side == 'B'):
buyCost += trade.price * trade.quantity
else:
sellCost += trade.price * trade.quantity
end = time.time() * 1000
duration = end - start
print(str(runNum) + " - duration " + str(int(duration)) + "ms\n")
print("buyCost = ", buyCost, " sellCost = ", sellCost, "\n")
if __name__ == '__main__':
trades = [PyMemTrade(0,0,0,0,0,0,'0') for i in range(NUM_RECORDS)]
for i in range (0, 5):
perfRun(i, trades)