Mercurial > hg > Game > Cerium
annotate example/regex_mas/time.pl @ 1786:ba6ffc679a8f draft
minor fix
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Nov 2013 21:06:44 +0900 |
parents | 3cfc65841ef7 |
children |
rev | line source |
---|---|
1681 | 1 #!/usr/bin/perl |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
2 |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
3 # update 7th August 2013 |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
4 # ./regex をcpu数と実行回数を設定して |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
5 # 実行時間のMAXとminとaverageを |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
6 # msで出力するスクリプト |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
7 |
1681 | 8 use strict; |
9 use warnings; | |
1685
3b8c12927f45
insert Math::Round in regex_mas/time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1683
diff
changeset
|
10 use Math::Round; #有効数字以下四捨五入 |
1681 | 11 |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
12 my $loop_counter = 0; |
1681 | 13 my $exec_result = 0; |
14 my $time_result = 0; | |
15 my $total_time = 0; | |
16 my $min_time = 0; | |
17 my $max_time = 0; | |
18 my $ave_time = 0; #average_time | |
1692
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
19 my $error_cnt = 0; |
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
20 my $looped_num = 0; |
1681 | 21 |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
22 if (@ARGV != 2) { |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
23 print("Usage: ./time.pl [cpu_num] [regex_exec_num]\n"); |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
24 exit(0); |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
25 } |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
26 |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
27 my $cpu_num = $ARGV[0]; |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
28 my $loop_num = $ARGV[1]; |
1681 | 29 print "------setting------\n"; |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
30 print " cpu_num = $cpu_num\n"; |
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
31 print "regex_exec_num = $loop_num\n"; |
1681 | 32 print "------result(ms)---\n"; |
33 | |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
34 while ($loop_counter < $loop_num){ |
1681 | 35 |
1683
0b38dd5439d5
insert error message regex_mas/time.pl .
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1681
diff
changeset
|
36 $exec_result = `./regex -file c.txt -cpu $cpu_num`; #実行時のコマンドをここで入力 |
1693 | 37 if($exec_result =~ /Time:/){ |
1692
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
38 if($exec_result =~ /(\d+\.\d+)/ ){ |
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
39 $time_result = $1 * 1000; #元の単位がsなので、ここでmsに変換 |
1681 | 40 |
1692
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
41 if($min_time == 0) {$min_time = $time_result}; |
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
42 if($time_result < $min_time) {$min_time = $time_result}; |
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
43 if($time_result > $max_time) {$max_time = $time_result}; |
1681 | 44 |
1692
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
45 $total_time += $time_result; |
1693 | 46 #print "Time:$time_result\n"; |
1692
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
47 ++$loop_counter; |
13ffed43fe68
bug fix time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1685
diff
changeset
|
48 } |
1681 | 49 } |
1693 | 50 ++$looped_num; |
1681 | 51 } |
52 | |
1685
3b8c12927f45
insert Math::Round in regex_mas/time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1683
diff
changeset
|
53 $ave_time = nearest(.001,$total_time / $loop_num); #小数点第4位未満四捨五入 (Math::Round) |
1681 | 54 |
55 print "max:$max_time\n"; | |
56 print "min:$min_time\n"; | |
1685
3b8c12927f45
insert Math::Round in regex_mas/time.pl
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1683
diff
changeset
|
57 print "ave:$ave_time\n"; |
1693 | 58 |
59 my $bug_num = $looped_num - $loop_counter; | |
60 print "bug_num:$bug_num\n"; |