# import sys # import numpy as np # from timeit import Timer # print(np.__version__, sys.version) # # results sensitive to hardware cache size # n = 5 # sizes = [2**20, 2**21, 2**22, 2**23] # stmts = [ # 'np.zeros(({},))', # 'np.random.rand({})', # 'np.linspace(0,1,{})', # 'np.exp(np.zeros(({},)))', # ] # for stmt in stmts: # for size in sizes: # s = stmt.format(size) # print(s+':') # t = Timer(s, globals=globals()).timeit(n) # print(f'\t{size/n/t} elements/second') #!/usr/bin/env python3 import sys import time import concurrent.futures import numpy as np SIZE = 16 * 1024 * 1024 PASSES = 100 THREADS = 64 print(np.__version__, sys.version) with open('/sys/kernel/mm/transparent_hugepage/enabled') as f: print(f.read()) def work(thread_id): arrs = [] for i in range(PASSES): arrs.append(np.ones(SIZE, np.uint8)) np.stack(arrs) with concurrent.futures.ThreadPoolExecutor(THREADS) as pool: start = time.monotonic() list(pool.map(work, range(THREADS))) stop = time.monotonic() print(stop - start) # import time # import numpy as np # start = time.monotonic() # N_GB = 10 # a = np.ones(N_GB * 1024 * 1024 * 1024, 'ubyte') # stop = time.monotonic() # print(stop - start)