Skip to content

Commit df383c7

Browse files
committed
ENH: Add benchmark for memory usage in pandas DataFrame creation
1 parent f2eb667 commit df383c7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pandas as pd
2+
import numpy as np
3+
import tracemalloc
4+
5+
def make_df(nrows=1_000_000):
6+
return pd.DataFrame({
7+
"a": np.random.randint(0, 100, size=nrows),
8+
"b": np.random.random(size=nrows),
9+
"c": np.random.choice(list("abcdefghijklmnopqrstuvwxyz"), size=nrows)
10+
})
11+
12+
df = make_df(200_000)
13+
tracemalloc.start()
14+
snap = df.snapshot("bench")
15+
snap_shot = tracemalloc.take_snapshot()
16+
top_stats = snap_shot.statistics('lineno')
17+
print("Top memory stats:", top_stats[:3])

0 commit comments

Comments
 (0)