I have a function that contains a for-loop with numerous actions that I am executing on dataframe with shape (68k,10) in a Jupyter notebook on Windows. My machine has a 11th gen Intel i7-1165G7 2.8Ghz processor (1.5 years old) with 16 GB of RAM.
The execution takes 2928 seconds, as evidenced by the following cProfile results. I am including the top tasks by execution time:
On my colleague's 4-year old Mac, this same function takes 191 seconds:
The built-in method nt.stat that takes 812 seconds on my machine doesn't even appear in my colleague's profiling results. I have also tried this on a 3-rd colleague's older Windows machine, and it takes longer than on mine. Why is there such a big difference in the execution time?
If helpful, I can try to include the entire cProfile results.
Update:
I created a reproducible example and ran on both machines.
Here is the code:
import numpy as np
import pandas as pd
import cProfile
df_shape = [100000, 8]
df = pd.DataFrame(np.random.uniform(0, 0.3, df_shape), index = pd.date_range('2022-01-01', periods=df_shape[0], freq='H'))
df.columns = ['loss_' + str(i) for i in range(df_shape[1])]
var_incoming = np.random.normal(550, 80, df.shape[0])
def test_func(df_, vars):
a_dct = {}
wf_dct = {}
res_lst = []
wf_res_lst = []
for i in range(df_.shape[0]):
y = vars[i]
for j, z in df_.iloc[i, :].items():
a = z * y
a_dct[j] = a
y = y * (1 - z)
wf_dct[j] = y
temp1 = pd.DataFrame(dict(a_dct), index=[df_.index[i]])
temp2 = pd.DataFrame(dict(wf_dct),
index=[df_.index[i]])
res_lst.append(temp1)
wf_res_lst.append(temp2)
res = pd.concat(res_lst, axis=0)
wf = pd.concat(wf_res_lst, axis=0)
return res, wf
The commands performed seem to be largely the same across the machines. The difference in execution is now smaller, and unfortunately, I no longer see the nt.stat command that was previously taking very long.