〜 タイム 〜
時間計測 (要KERNEL32.DLL)

パソコンを起動させてからの時間取得サンプルの応用で、処理時間を計測するサンプルを紹介します。
gettime命令・関数を使って処理時間を計測する際、日をまたぐだけで結果がおかしくなってしまいますが、
起動させてからの時間を取得するGetTickCountAPIを使うことで、
1週間程度連続で計測させ続ける程度では正常な値を取得できる…と思います(未検証)
	

getoptime 受取先
受取先起動してからの経過時間(ミリ秒単位)を格納する数値型変数を指定する。

timewatch 保持変数
保持変数開始時に保持した変数を指定する。
尚、保持変数は計測結果で上書きされる。

 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
	ll_libload kernel, "kernel32.dll"
	ll_getproc GetTickCount, "GetTickCount", kernel

#module
#deffunc getoptime val
	mref time, 16
	ll_callfnv GetTickCount@
	ll_ret time
	return

#deffunc timewatch val
	mref time2, 16
	i = time
	getoptime time2
	time2 -= i
	return
#global

	num = 10
	dim t, num
	repeat num
		getoptime t.cnt
		repeat 1000000 : tmp++ : loop // インクリメントを100万回計測
		timewatch t.cnt
		mes "" + cnt + ". " + t.cnt + "ms"
	loop
	mes "--------"
	repeat num
		if cnt : tmp += t.cnt : else : tmp = t.cnt
	loop
	tmp = tmp / num, tmp * 100 / num \ 100
	mes "平均" + tmp + "." + tmp.1 + "ms"
	stop

経過時間 = getoptime( )
経過時間起動してからの経過時間(ミリ秒単位)の格納先を指定する。
[パラメータなし]経過時間を取得するだけのため、パラメータは必要ない。

結果 = timewatch(保持変数)
結果計測結果の代入先を指定する。
保持変数開始時に保持した変数を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#uselib "kernel32.dll"
#cfunc global getoptime "GetTickCount"

#module
#defcfunc timewatch var tms, local tme
	return getoptime() - tms
#global

	num = 10
	dim t, num
	repeat num
		t.cnt = getoptime()
		repeat 1000000 : tmp++ : loop // インクリメントを100万回計測
		t.cnt = timewatch(t.cnt)
		mes "" + cnt + ". " + t.cnt + "ms"
	loop
	mes "--------"
	repeat num
		if cnt : tmp += t.cnt : else : tmp = t.cnt
	loop
	mes "平均" + (1.0 * tmp / num) + "ms"