Last active
November 19, 2024 06:24
-
-
Save michaeldorner/c0fba1bc108fa230afd40d1d63d5df97 to your computer and use it in GitHub Desktop.
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 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'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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.