ほい、ということでプロファイルをとってみた。
daisuke@beefcake DateTime-TimeZone-XS$ perl -Mblib -d:DProf test.pl
timethis 50: 43 wallclock secs (24.05 usr + 6.99 sys = 31.04 CPU) @ 1.61/s (n=50)daisuke@beefcake DateTime-TimeZone-XS$ dprofpp
<snip>
Total Elapsed Time = 12.00626 Seconds
User+System Time = 2.216263 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
197. 4.368 4.368 38300 0.0001 0.0001 DateTime::TimeZone::spans
77.5 1.719 2.324 19202 0.0001 0.0001 DateTime::TimeZone::new
41.5 0.921 4.453 38300 0.0000 0.0001 DateTime::TimeZone::_spans_binary_
search
19.1 0.424 0.424 19603 0.0000 0.0000 Params::Validate::_validate
15.5 0.345 0.332 19202 0.0000 0.0000 DateTime::_calc_local_components
12.6 0.281 1.890 19200 0.0000 0.0001 DateTime::_handle_offset_modifier
5.96 0.132 2.166 19202 0.0000 0.0001 DateTime::_calc_local_rd
5.05 0.112 6.284 19150 0.0000 0.0003 DateTime::set_time_zone
4.29 0.095 0.095 432 0.0002 0.0002 DateTime::TimeZone::xs_register
3.47 0.077 0.077 1196 0.0001 0.0001 DateTime::TimeZone::find
2.30 0.051 0.146 432 0.0001 0.0003 DateTime::TimeZone::register
2.21 0.049 0.211 20 0.0025 0.0106 DateTime::BEGIN
1.67 0.037 0.061 786 0.0000 0.0001 DateTime::TimeZone::BEGIN
1.53 0.034 0.071 299 0.0001 0.0002 DateTime::Locale::_register
1.31 0.029 0.317 4 0.0074 0.0792 main::BEGIN
おーっと、spans()を呼び過ぎだ。これは元のPurePerlコードが$tz->{spans}を直接扱うので、例えばspanリストのサイズとかを必要とする時にscalar @spansみたいな事をしないといけないからだと思ったので、
IV spans_len(self); /* spansのリスト数を取得 */
IV span_at(self, i); /* i個目のspan要素を取得 */
SV *max_span(self); /* 最大のspanを取得 */
というメソッドを追加
daisuke@beefcake DateTime-TimeZone-XS$ dprofpp
<snip>
Total Elapsed Time = 7.434086 Seconds
User+System Time = 0 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
0.00 1.490 2.259 19202 0.0001 0.0001 DateTime::TimeZone::new
0.00 0.543 0.588 19202 0.0000 0.0000 DateTime::_calc_local_components
0.00 0.504 0.504 19603 0.0000 0.0000 Params::Validate::_validate
0.00 0.157 0.041 19202 0.0000 0.0000 DateTime::_calc_local_rd
0.00 0.130 -0.462 38300 0.0000 - DateTime::TimeZone::_span_for_date
0.0000 time
0.00 0.099 0.099 1196 0.0001 0.0001 DateTime::TimeZone::find
0.00 0.096 0.096 38300 0.0000 0.0000 DateTime::TimeZone::max_span
0.00 0.076 -0.423 19200 0.0000 - DateTime::_handle_offset_modifier
0.00 0.068 0.113 786 0.0001 0.0001 DateTime::TimeZone::BEGIN
0.00 0.066 0.066 38300 0.0000 0.0000 DateTime::utc_rd_as_seconds
0.00 0.056 0.056 432 0.0001 0.0001 DateTime::TimeZone::xs_register
0.00 0.052 0.108 432 0.0001 0.0002 DateTime::TimeZone::register
0.00 0.051 0.051 140900 0.0000 0.0000 DateTime::TimeZone::span_at
0.00 0.040 0.108 7 0.0057 0.0154 DateTime::Locale::BEGIN
0.00 0.040 0.319 4 0.0099 0.0797 main::BEGIN
daisuke@beefcake DateTime-TimeZone-XS$
おお、消えた。スバラシ。