/
benchmark.py
53 lines (40 loc) · 1.71 KB
/
benchmark.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
53
__author__ = 'brian'
"""
Output in test run:
Looking up 10 keys from Google Finance
Time to download 10 stocks from Google with Multi-Threading : 6.987292528152466 seconds.
Looking up 10 keys from Google Finance
Time to download 10 stocks from Google with Multi Processing : 6.1684489250183105 seconds.
Looking up 10 keys from Google Finance
Time to download 10 stocks from Google with Single Threading : 7.67667818069458 seconds.
Process finished with exit code 0
"""
import concurrentpandas
import time
# Define your keys
finance_keys = ["aapl", "xom", "msft", "goog", "brk-b", "TSLA", "IRBT", "VTI", "VT", "VNQ"]
# Instantiate Concurrent Pandas
fast_panda = concurrentpandas.ConcurrentPandas()
# Set your data source
fast_panda.set_source_google_finance()
# Insert your keys
fast_panda.insert_keys(finance_keys)
# Choose either asynchronous threads, processes, or a single sequential download
pre = time.time()
fast_panda.consume_keys_asynchronous_threads()
post = time.time()
print("Time to download 10 stocks from Google with Multi-Threading : " + (post - pre).__str__() + " seconds.")
# Insert your keys
fast_panda.insert_keys(finance_keys)
# Choose either asynchronous threads, processes, or a single sequential download
pre = time.time()
fast_panda.consume_keys_asynchronous_processes()
post = time.time()
print("Time to download 10 stocks from Google with Multi Processing : " + (post - pre).__str__() + " seconds.")
# Insert your keys
fast_panda.insert_keys(finance_keys)
# Choose either asynchronous threads, processes, or a single sequential download
pre = time.time()
fast_panda.consume_keys()
post = time.time()
print("Time to download 10 stocks from Google with Single Threading : " + (post - pre).__str__() + " seconds.")