Last active
April 26, 2023 19:37
-
-
Save TheArcherST/6c827b22401701d3887d7016e7493fb4 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
from timeit import timeit | |
import plotly.express as px | |
import pandas as pd | |
EXPRESSIONS = [ | |
"{v: k for k, v in data.items()}", | |
"dict(zip(data.values(), data.keys()))", | |
"new = {}\nfor k, v in data.items(): new[k] = v", | |
] | |
NUMBER = 100_000 | |
SET_LEN = 100 | |
df = pd.DataFrame(columns=EXPRESSIONS) | |
for n, set_l in enumerate(range(SET_LEN)): | |
data = {i: i+1 for i in range(1, set_l*2, 2)} | |
results = [timeit(expr, globals={"data": data}, number=NUMBER) | |
for expr in EXPRESSIONS] | |
df.loc[n] = results | |
fig = px.line(df) | |
fig.update_layout(xaxis_title="elements count, N", | |
yaxis_title=f"time, s/{NUMBER}") | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment