Last active
October 25, 2021 13:44
-
-
Save meksor/30902f8f8ce6bc07f0c4c27c1125d053 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
from profiled import profiled | |
from ixmp import TimeSeries, Platform | |
import pandas as pd | |
import cProfile | |
import io | |
import pstats | |
import contextlib | |
@contextlib.contextmanager | |
def profiled(): | |
pr = cProfile.Profile() | |
pr.enable() | |
yield | |
pr.disable() | |
s = io.StringIO() | |
ps = pstats.Stats(pr, stream=s).sort_stats("cumulative") | |
ps.print_stats() | |
# uncomment this to see who's calling what | |
# ps.print_callers() | |
print(s.getvalue()) | |
ndps = 120_000 | |
mp = Platform("local") | |
ts = TimeSeries(mp, "Model", "Scen", version="new") | |
def make_dp(i): | |
return ("region", "variable", "unit", i, 1.23) | |
dps = [make_dp(i) for i in range(ndps)] | |
df = pd.DataFrame(dps, columns=["region", "variable", "unit", "year", "value"]) | |
print(df) | |
with profiled(): | |
ts.add_timeseries(df) | |
ts.commit("test") | |
with profiled(): | |
df2 = ts.timeseries() | |
print(df2) |
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
from ixmp.db.models import * | |
from ixmp.core.platform import Platform | |
from ixmp.core.scenario import Scenario | |
from ixmp.core.models import DataPoint | |
from datetime import datetime | |
from profiled import profiled | |
import pandas as pd | |
import cProfile | |
import io | |
import pstats | |
import contextlib | |
@contextlib.contextmanager | |
def profiled(): | |
pr = cProfile.Profile() | |
pr.enable() | |
yield | |
pr.disable() | |
s = io.StringIO() | |
ps = pstats.Stats(pr, stream=s).sort_stats("cumulative") | |
ps.print_stats() | |
# uncomment this to see who's calling what | |
# ps.print_callers() | |
print(s.getvalue()) | |
ndps = 300_000 | |
mp = Platform("test2") | |
s = Scenario(mp, "Model 100", "Scenario 100", version="new") | |
now = datetime.utcnow().isoformat() | |
def make_dp(): | |
return ( | |
"Region 1", | |
"Quantity 0", | |
"Unit 0", | |
DataPoint.Type.BASE.value, | |
0.0, | |
1999, | |
now, | |
"category", | |
) | |
df = pd.DataFrame( | |
[make_dp() for _ in range(ndps)], | |
columns=[ | |
"region", | |
"quantity", | |
"unit", | |
"type", | |
"value", | |
"step_year", | |
"step_datetime", | |
"step_category", | |
], | |
) | |
print(df) | |
with profiled(): | |
df = s.add_datapoints(df) | |
with profiled(): | |
df = s.tabulate_datapoints() | |
print(df) |
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 matplotlib.pyplot as plt | |
def plot_create(ax): | |
ixmp_cur = ([ | |
10, | |
50, | |
100, | |
120 | |
], [0.504, 21.020, 81.933, 114.865]) | |
ixmp_next = ([ | |
10, | |
50, | |
100, | |
200, | |
300, | |
500 | |
], [0.342, 1.957, 3.593, 7.628, 12.313, 20.262]) | |
ax.plot(*ixmp_next,'go--', *ixmp_cur, 'bo--') | |
ax.set(ylabel='secs') | |
ax.set_title("Add") | |
def plot_read(ax): | |
ixmp_cur = ([ | |
10, | |
50, | |
100, | |
120 | |
], [0.239, 1.078, 2.060, 2.340]) | |
ixmp_next = ([ | |
10, | |
50, | |
100, | |
200, | |
300, | |
500 | |
], [0.037, 0.389, 0.617, 1.017, 1.686, 2.835]) | |
ax.plot(*ixmp_next,'g*--', *ixmp_cur, 'b*--') | |
ax.set(xlabel='1000x data points', ylabel='secs') | |
ax.set_title("Tabulate") | |
fig, (ax1, ax2) = plt.subplots(2) | |
plot_create(ax1) | |
plot_read(ax2) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment