Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Py.py #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions Py.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time
NUM_RECORDS = 50* 1000 * 444
NUM_RECORDS = 50 * 1000 * 444

class PyMemTrade():
class PyMemTrade(object):
__slots__ = ('tradeId', 'clientId', 'venueId', 'instrumentCode','price','quantity','side')
def __init__(self, tradeId, clientId, venueId, instrumentCode, price, quantity, side):
self.tradeId = tradeId
self.clientId = clientId
Expand All @@ -10,33 +11,43 @@ def __init__(self, tradeId, clientId, venueId, instrumentCode, price, quantity,
self.price = price
self.quantity = quantity
self.side = side


def initTrades(trades):
for i in range(0, NUM_RECORDS):
aside = ''
if (i % 2 == 0):
aside = 'B'
else:
aside = 'S'
trades[i] = PyMemTrade(i,1,123,321,i,i,aside)
for i in xrange(0, NUM_RECORDS):
t = trades[i]
t.tradeId = i
t.clientId = 1
t.venueId = 123
t.instrumentCode = 321
t.price = i
t.quantity = i

if (i % 2 == 0):
t.side = 'B'
else:
t.side = 'S'



def perfRun(runNum, trades):
start = time.time() * 1000
initTrades(trades)
buyCost = 0
sellCost = 0
for i in range(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(runNum, " - duration ", duration, "ms\n") This prints weird on Pypy
print("buyCost = ", buyCost, " sellCost = ", sellCost, "\n")
start = time.time() * 1000
initTrades(trades)
buyCost = 0
sellCost = 0
for i in xrange(0, NUM_RECORDS):
t = trades[i]

if (t.side == 'B'):
buyCost += t.price * t.quantity
else:
sellCost += t.price * t.quantity

end = time.time() * 1000
duration = end - start
print(str(runNum) + " - duration " + str(int(duration)) + "ms\n")
#print(runNum, " - duration ", duration, "ms\n") This prints weird on Pypy
print("buyCost = ", buyCost, " sellCost = ", sellCost, "\n")

if __name__ == '__main__':
trades = [PyMemTrade(0,0,0,0,0,0,'0') for i in range(NUM_RECORDS)]
Expand Down