最初のリサーチは大事ですね。
[root@hoge tmp]# date +"%F %T 0.%3N" ; ./mydate.pl ; date +"%F %T 0.%3N" ; ./mydate.pl 2017-01-27 07:53:22 0.131 2017-01-27 07:53:22 0.133 2017-01-27 07:53:22 0.133 2017-01-27 07:53:22 0.135 [root@hoge tmp]# /usr/bin/time -v date +"%F %T 0.%3N" 2017-01-27 07:53:36 0.230 Command being timed: "date +%F %T 0.%3N" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 93% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 724 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 228 Voluntary context switches: 1 Involuntary context switches: 1 Swaps: 0 File system inputs: 0 File system outputs: 8 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 [root@hoge tmp]# /usr/bin/time -v ./mydate.pl 2017-01-27 07:53:46 0.445 Command being timed: "./mydate.pl" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 100% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 2300 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 634 Voluntary context switches: 1 Involuntary context switches: 1 Swaps: 0 File system inputs: 0 File system outputs: 8 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 [root@hoge tmp]# time date +"%F %T 0.%3N" 2017-01-27 07:56:18 0.292 real 0m0.001s user 0m0.000s sys 0m0.001s [root@hoge tmp]# time ./mydate.pl 2017-01-27 07:56:30 0.545 real 0m0.002s user 0m0.001s sys 0m0.001s [root@hoge tmp]#このように、当然、perl で書いたら重い (と言ったって2ミリくらいだけど) ですね。手持ちの新旧VM環境を調べたところ、現在の RHEL/CentOS系 (RHEL3 以降) なら %N を使えるようです。というわけで、せっかく書いた mydate.pl は、お蔵入り。
2017-02-02追記
お手軽に性能計測と言えば、昔から time コマンドを使ってましたが、最近は perf stat が使えるので、備忘録です。
time コマンドよりも精細な計測が出来るので、今回のように処理時間が極く短いモノを測る場合は、こちらを利用すると良いようです。
[root@hoge tmp]# perf stat ./mydate.pl 2017-02-02 03:21:50 0.747 Performance counter stats for './mydate.pl': 1.504866 task-clock (msec) # 0.886 CPUs utilized 0 context-switches # 0.000 K/sec 0 cpu-migrations # 0.000 K/sec 592 page-faults # 0.393 M/sec 4,952,896 cycles # 3.291 GHz (33.77%) 2,461,931 stalled-cycles-frontend # 49.71% frontend cycles idle 2,461,430 stalled-cycles-backend # 49.70% backend cycles idle 4,000,101 instructions # 0.81 insn per cycle # 0.62 stalled cycles per insn 760,869 branches # 505.606 M/sec 31,136 branch-misses # 4.09% of all branches (88.50%) 0.001698771 seconds time elapsed [root@hoge tmp]# perf stat date +"%F %T 0.%3N" 2017-02-02 03:39:52 0.612 Performance counter stats for 'date +%F %T 0.%3N': 0.355000 task-clock (msec) # 0.658 CPUs utilized 0 context-switches # 0.000 K/sec 0 cpu-migrations # 0.000 K/sec 193 page-faults # 0.544 M/sec 1,193,873 cycles # 3.363 GHz 800,322 stalled-cycles-frontend # 67.04% frontend cycles idle 636,341 stalled-cycles-backend # 53.30% backend cycles idle 785,182 instructions # 0.66 insn per cycle # 1.02 stalled cycles per insn 144,848 branches # 408.023 M/sectime コマンドによる計測では、mydate.pl は、date コマンドより2倍程度の重さに見えてましたが、perf stat で計ると、4倍程度重いという結果が見てとれました。branch-misses 0.000539333 seconds time elapsed [root@hoge tmp]#
0 件のコメント:
コメントを投稿