Pythonデータサイエンスクックブック

(2順目)

レシピ5.2

x, y, z = np.random.rand(3, 1000000)  
print(x)  
print(y)  
print(z)  
print(x.shape)
print(y.shape)
print(z.shape)


[ 0.02446522  0.53300813  0.08588861 ...,  0.51124115  0.99969485  0.431258  ]
[ 0.93027085  0.71045152  0.23566422 ...,  0.30943928  0.61953679
  0.41338103]
[ 0.724853    0.86620411  0.93741716 ...,  0.72326703  0.27723427
  0.45690644]
(1000000,)
(1000000,)
(1000000,)

3項の結果

100 loops, best of 3: 17.7 ms per loop

4項の結果

The slowest run took 5.86 times longer than the fastest. This could mean that an intermediate result is being cached 
100 loops, best of 3: 2.8 ms per loop

17.7/2.8=6.3倍

5項 スレッドを20まで拡大してみた

1  thread 
100 loops, best of 3: 5.63 ms per loop
2  thread 
100 loops, best of 3: 3.67 ms per loop
3  thread 
100 loops, best of 3: 3.02 ms per loop
4  thread 
100 loops, best of 3: 2.92 ms per loop
5  thread 
100 loops, best of 3: 2.86 ms per loop
6  thread 
100 loops, best of 3: 2.82 ms per loop
7  thread 
100 loops, best of 3: 2.8 ms per loop
8  thread 
100 loops, best of 3: 2.8 ms per loop
9  thread 
100 loops, best of 3: 2.79 ms per loop
10  thread 
100 loops, best of 3: 2.79 ms per loop
11  thread 
100 loops, best of 3: 2.81 ms per loop
12  thread 
100 loops, best of 3: 2.82 ms per loop
13  thread 
100 loops, best of 3: 2.81 ms per loop
14  thread 
100 loops, best of 3: 2.81 ms per loop
15  thread 
100 loops, best of 3: 2.82 ms per loop
16  thread 
100 loops, best of 3: 2.81 ms per loop
17  thread 
100 loops, best of 3: 2.83 ms per loop
18  thread 
100 loops, best of 3: 2.82 ms per loop
19  thread 
100 loops, best of 3: 2.82 ms per loop
20  thread 
100 loops, best of 3: 2.84 ms per loop

むやみにスレッドを増やしても効果がない。

レシピ5.3

Cコンパイラが動作しないのであきらめる