Last active
February 22, 2023 13:47
-
-
Save michaeldorner/c0fba1bc108fa230afd40d1d63d5df97 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 | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
# measuring | |
numpy_results = {} | |
python_results = {} | |
config = {'number': 100, 'repeat': 100} | |
sizes = [2**exp for exp in range(12)] # or np.arange(12) ;-) | |
for size in sizes: | |
numpy_results[size] = min(timeit.repeat(f'np.arange({size})', setup='import numpy as np', **config)) | |
python_results[size] = min(timeit.repeat(f'list(range({size}))', **config)) | |
df = pd.concat((pd.Series(numpy_results, name='np.arange'), pd.Series(python_results, name='range')), axis=1) | |
# plotting | |
fig, ax = plt.subplots() | |
df.plot(ax=ax) | |
ax.set_xscale('log', base=2) | |
ax.set_xticks(sizes) | |
ax.set_xticklabels(sizes) | |
ax.set_xlabel('Size') | |
ax.set_ylabel('Best runtime for 10 runs out of 10 repetition') |
Author
michaeldorner
commented
Feb 22, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment