Created
November 30, 2015 16:43
-
-
Save vain0x/5aeda019eb11835987f4 to your computer and use it in GitHub Desktop.
簡易ベンチマークモジュール (HSP3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ベンチマーク用モジュール | |
/* | |
// デバッグ用コードを除去 | |
#undef _debug | |
#undef assert | |
#define global assert(%1) : | |
#undef logmes | |
#define global logmes(%1) : | |
//*/ | |
#include "d3m.hsp" // for d3timer | |
#module | |
// 平均 | |
#defcfunc arrlen_sorted_mean array self, int len, \ | |
local sum | |
assert@hsp len >= 0 | |
sum = double(0) | |
repeat len | |
sum += self(cnt) | |
loop | |
if ( len >= 3 ) { | |
// 最大値と最小値を除く | |
return (sum - self(0) - self(len - 1)) / (len - 2) | |
} | |
return sum / len | |
// 中央値 | |
#defcfunc arrlen_sorted_median array self, int len | |
assert@hsp len >= 1 | |
return double(self((len - 1) / 2)) / 2 + double(self(len / 2)) / 2 | |
#global | |
#module | |
// ラベルの実行時間を計測 | |
#define global benchmark_logmes(%1, %2, %3 = cnt_trial) %tbenchmark %i0 \ | |
%p = (%1) :\ | |
benchmark_logmes__ %p, (%2), (%3) :\ | |
%o0 | |
#deffunc benchmark_logmes__ var lb_proc, str msg, int times | |
dim record, times | |
repeat times | |
begin_time = d3timer() | |
gosub lb_proc | |
record(cnt) = d3timer() - begin_time | |
loop | |
sortval record | |
/* | |
repeat times | |
logmes@hsp strf("#%2d: %d ms", cnt, record(cnt)) | |
loop | |
//*/ | |
//出力 | |
logmes@hsp "計測結果: " + msg | |
logmes@hsp "平均: " + arrlen_sorted_mean(record, times) + "ms" | |
logmes@hsp "中央: " + arrlen_sorted_median(record, times) + "ms" | |
return | |
#global |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment