Created
July 28, 2020 07:19
-
-
Save CloudyPadmal/5baf0da378c5661858ef17c058faafbb to your computer and use it in GitHub Desktop.
Compare timing for loop merge operations using different methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import random | |
import numpy as np | |
A = [random.random() for i in range(65536)] | |
B = [random.random() for i in range(65536)] | |
C = [random.random() for i in range(65536)] | |
D = [random.random() for i in range(65536)] | |
E = [random.random() for i in range(65536)] | |
F = [random.random() for i in range(65536)] | |
a = time.time() | |
X = []; Y = []; Z = [] | |
for i in range(65536): | |
X.append(A[i]) | |
X.append(D[i]) | |
Y.append(B[i]) | |
Y.append(E[i]) | |
Z.append(C[i]) | |
Z.append(F[i]) | |
Q = (X, Y, Z) | |
a = (time.time() - a) | |
b = time.time() | |
Q = ([*A, *D], [*B, *E], [*C, *F]) | |
b = (time.time() - b) | |
c = time.time() | |
Q = (np.concatenate((A, D)), np.concatenate((B, E)), np.concatenate((C, F))) | |
c = time.time() - c | |
print('1. For loop: %f;\n2. Pointers: %f;\n3. Numpy : %f;' % (a, b, c)) |
Author
CloudyPadmal
commented
Jul 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment