-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathBenchmark.py
More file actions
31 lines (28 loc) · 784 Bytes
/
Copy pathBenchmark.py
File metadata and controls
31 lines (28 loc) · 784 Bytes
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
from Orderbook import Orderbook
from Order import *
from Trade import Trade
from random import getrandbits, randint, random
# Benchmark
OB = Orderbook()
numOrders = 10**7
orders = []
for n in range(numOrders):
if bool(getrandbits(1)):
orders.append(LimitOrder(n, Side.BUY, randint(1, 200), randint(1, 4)))
else:
orders.append(LimitOrder(n, Side.SELL, randint(1, 200), randint(1, 4)))
from time import time
start = time()
for order in orders:
OB.processOrder(order)
end = time()
totalTime = (end-start)
print("Time: " + str(totalTime))
print("Time per order (us): " + str(1000000*totalTime/numOrders))
print("Orders per second: " + str(numOrders/totalTime))
"""
Output
Time: 25.271270990371704
Time per order (us): 2.5271270990371706
Orders per second: 395706.25489354995
"""