Created
July 6, 2020 10:51
-
-
Save FirefoxMetzger/cd1690b8fed8cbd4497a8dd38f2c093a to your computer and use it in GitHub Desktop.
This file contains 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 timeit | |
number = 10000 | |
numpy_time = timeit.timeit("[np.random.rand() for _ in range(int(1e3))]", "import numpy as np", number=number) | |
random_time = timeit.timeit("[random.random() for _ in range(int(1e3))]", "import random", number=number) | |
numpy_batch_time = timeit.timeit("np.random.rand(int(1e3))", "import numpy as np", number=number) | |
print("Timings") | |
print("=======") | |
print(f"Numpy Single: {numpy_time:.3f}") | |
print(f"Random: {random_time:.3f}") | |
print(f"Numpy Batch: {numpy_batch_time:.3f}") | |
print("=======") | |
# ======= | |
# Numpy Single: 3.245 | |
# Random: 1.003 | |
# Numpy Batch: 0.085 | |
# ======= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment