I'm looking to optimize a program I've written and I'm really coming across some stumbling blocks. I have so many questions, I don't know where to begin but, for starters, I'll try to keep it simplified to an obstacle I can't seem to overcome.
The code I'm writing is a small schedule generator for work which requires 24/7 coverage. Each shift covers a two-week time span (some shifts rotate over a two week period but the coverage requirements must be maintained - which is why I have to use 14 days). As of right now, I'm trying to figure out the fastest way to check whether a combination of shifts adds up to the right number of people on a given day. I keep hearing Numpy is super fast at this type of stuff but when I run the following:
import numpy as np
import time
c_ar = np.array([1,1,1,1,0,0,0,1,1,1,1,0,0,0])
d_ar = np.array([0,0,0,1,1,1,1,0,0,0,1,1,1,1])
e_ar = np.array([0,0,0,1,1,1,1,0,0,0,1,1,1,1])
m_ar = np.array([0,1,1,0,1,1,0,0,1,1,0,1,1,0])
p_ar = np.array([1,1,0,0,0,1,1,1,1,0,0,0,1,1])
t0 = time.time()
x = c_ar[0] + d_ar[0] + e_ar[0] + m_ar[0] + p_ar[0]
t1 = time.time()
print t1-t0
I get back:
2.19345092773e-05
However, if I run:
c = [1,1,1,1,0,0,0,1,1,1,1,0,0,0]
d = [0,0,0,1,1,1,1,0,0,0,1,1,1,1]
e = [0,0,0,1,1,1,1,0,0,0,1,1,1,1]
m = [0,1,1,0,1,1,0,0,1,1,0,1,1,0]
p = [1,1,0,0,0,1,1,1,1,0,0,0,1,1]
t2 = time.time()
y = c[0] + d[0] + e[0] + m[0] + p[0]
t3 = time.time()
print t3-t2
I get back:
1.90734863281e-06
Am I missing something about Numpy that would make it faster than my example? Also, is there an even faster way than the two methods I used above?