import numpy as np import time NUM_ELEMENTS = 50000000 a = list(range(NUM_ELEMENTS)) b = list(range(NUM_ELEMENTS)) c = [] start_time = time.process_time() for i in range(len(a)): c.append(a[i] + b[i]) end_time = time.process_time() print(f"Time taken for adding two lists/arrays of {NUM_ELEMENTS} elements to create a third.") print() print(f"Time taken for Python's lists with an explicit loop: {end_time - start_time} seconds") start_time = time.process_time() c = [x + y for x, y in zip(a, b)] end_time = time.process_time() print(f"Time taken for Python's lists with no explicit loop but using zip(): {end_time - start_time} seconds") a_np = np.arange(NUM_ELEMENTS) b_np = np.arange(NUM_ELEMENTS) start_time = time.process_time() c_np = a_np + b_np # Single vectorized operation end_time = time.process_time() print(f"Time taken for nparray with vectorization: {end_time - start_time} seconds")