[fpr 3836] Pythonの速さ

Yasuharu Okamoto


岡本です。

先ほどのスクリプト、t_endの場所を間違えていました。
正しくは以下のようになります。

from datetime import datetime

def get_MicroSec():
    now = datetime.now()
    return now.microsecond + 1000000.0 * (now.second + 60.0 * (now.minute \
                            + 60.0 * now.hour))

check_time = [0]*100
t0 = 0
t_start = get_MicroSec()
t1 = get_MicroSec()    
for i in range(100):
    t0 = t1
    t1 = get_MicroSec()         check_time[i] = t1 - t0

t_end = get_MicroSec()

for i in range(100):
    print("{0:10}".format(check_time[i]), end='')

print("\n\nt_end - t_start = {0}microsecond\n\n".format(t_end - t_start))
    
t0 = 0
t1 = get_MicroSec()    
pos = 0
while(pos < 100):
    t0 = t1
    t1 = get_MicroSec()  
    if t1 > t0:
        check_time[pos] = t1 - t0
        pos += 1

for i in range(100):
    print("{0:10}".format(check_time[i]), end='')

実行結果
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
============ RESTART: M:/PythonSamples_1/CheckTime/CheckTime_1.py
============
       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0       0.0       0.0       0.0
0.0       0.0       0.0       0.0       0.0

t_end - t_start = 0.0microsecond


   15605.0   15623.0   15628.0   15621.0   15632.0   15626.0   15640.0
15624.0   15605.0   15627.0   15643.0   15625.0   15625.0   15625.0   15624.
0   15625.0   15625.0   15628.0   15623.0   15626.0   15603.0   15625.0
15625.0   15625.0   15628.0   15621.0   15629.0   15625.0   15622.0   15624.
0   15628.0   15627.0   15623.0   15644.0   15626.0   15603.0   15625.0
15627.0   15626.0   15624.0   15628.0   15622.0   15626.0   15627.0   15624.
0   15626.0   15623.0   15643.0   15625.0   15603.0   15626.0   15624.0
15626.0   15624.0   15629.0   15623.0   15627.0   15625.0   15644.0   15625.
0   15624.0   15605.0   15647.0   15605.0   15642.0   15605.0   15625.0
15624.0   15648.0   15604.0   15631.0   15620.0   15624.0   15646.0   15624.
0   15625.0   15625.0   15625.0   15625.0   15625.0   15625.0   15625.0
15626.0   15620.0   15630.0   15624.0   15605.0   15624.0   15645.0   15605.
0   15629.0   15625.0   15621.0   15646.0   15604.0   15626.0   15625.0
15627.0   15625.0   15625.0
>>>

Forループでの100回の繰り返しの経過時間も0microsecondです。

横浜市在住
岡本安晴





スレッド表示 著者別表示 日付順表示 トップページ
["

\e$B$3$3$O\e(B\e$B?4M}3X8&5f$N4pAC%a!<%j%s%0%j%9%H\e(B\e$B$KEj9F$5$l$?2a5n$N5-;v$r7G:\\$7$F$$$k%Z!<%8$G$9!#\e(B

\n", "\n"]