forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_refactor.py
51 lines (38 loc) · 1.16 KB
/
bench_refactor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from pandas import *
from pandas.compat import range
try:
import pandas.core.internals as internals
reload(internals)
import pandas.core.frame as frame
reload(frame)
from pandas.core.frame import DataFrame as DataMatrix
except ImportError:
pass
N = 1000
K = 500
def horribly_unconsolidated():
index = np.arange(N)
df = DataMatrix(index=index)
for i in range(K):
df[i] = float(K)
return df
def bench_reindex_index(df, it=100):
new_idx = np.arange(0, N, 2)
for i in range(it):
df.reindex(new_idx)
def bench_reindex_columns(df, it=100):
new_cols = np.arange(0, K, 2)
for i in range(it):
df.reindex(columns=new_cols)
def bench_join_index(df, it=10):
left = df.reindex(index=np.arange(0, N, 2),
columns=np.arange(K // 2))
right = df.reindex(columns=np.arange(K // 2 + 1, K))
for i in range(it):
joined = left.join(right)
if __name__ == '__main__':
df = horribly_unconsolidated()
left = df.reindex(index=np.arange(0, N, 2),
columns=np.arange(K // 2))
right = df.reindex(columns=np.arange(K // 2 + 1, K))
bench_join_index(df)