File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ import numpy as np
3+ import timeit
4+
5+
6+ # Python float is 64 bit / 8 byte
7+ array_size = 1000 * 1000 * 10
8+ print ("Size of data array: {} MB" .format (array_size * 8 / (1000 * 1000 )))
9+
10+ N = 10
11+
12+ SETUP = """
13+ array1 = np.ones(array_size)
14+ array2 = np.ones(array_size)
15+ buffer_array = np.empty(array_size)
16+ """
17+
18+
19+ print ("### Storing" )
20+ index_map = np .arange (0 , array_size )
21+ def storing (array1 , array2 ):
22+ buffer_array = array1 [index_map ] + array2 [index_map ]
23+ # return buffer_array
24+
25+ total_time = timeit .timeit (
26+ "storing(array1, array2)" ,
27+ number = 10 ,
28+ setup = SETUP ,
29+ globals = globals ()
30+ )
31+ print (total_time / N )
32+
33+
34+ print ("### Not storing" )
35+ index_map = np .arange (0 , array_size )
36+ def not_storing (array1 , array2 ):
37+ array1 [index_map ] + array2 [index_map ]
38+
39+ total_time = timeit .timeit (
40+ "not_storing(array1, array2)" ,
41+ number = 10 ,
42+ setup = SETUP ,
43+ globals = globals ()
44+ )
45+ print (total_time / N )
You can’t perform that action at this time.
0 commit comments