-
Notifications
You must be signed in to change notification settings - Fork 3
/
timeFunctionCalls.py
52 lines (40 loc) · 1.52 KB
/
timeFunctionCalls.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
44
45
46
47
48
49
50
51
52
import sys
import time
import timeit
import uuid
def testFun(payload=[]):
ts = int(time.time())
if isinstance(payload, dict):
payload = [payload] # it was a single document
commonHeaders = {'type': "doc_type",
'version': 0.2,
'producer': "producer_blah"}
docs = []
for doc in payload:
notification = {}
notification.update(commonHeaders)
# Add body consisting of the payload and metadata
body = {'payload': doc,
'metadata': {'timestamp': ts,
'id': "docId_Blah",
'uuid': str(uuid.uuid4())}
}
notification['body'] = body
docs.append(notification)
return docs
def testFunSingle(numTimes):
for i in range(0, numTimes):
testFun([{str(i): i}])
def main():
myDict = {}
numTimes = int(1e6)
for i in range(0, numTimes):
myDict.update({str(i): i})
# print "Started evaluation of single function call at: %s" % (datetime.utcnow())
ti = timeit.timeit("testFun([%s])" % myDict, setup="from __main__ import testFun", number=1)
print "Finished single function call in %s secs" % ti
# print "Started evaluation of %d function calls at: %s" % (numTimes, datetime.utcnow())
ti = timeit.timeit("testFunSingle(%d)" % numTimes, setup="from __main__ import testFunSingle", number=1)
print "Finished %d function calls in %s secs" % (numTimes, ti)
if __name__ == "__main__":
sys.exit(main())