I have a question on DateTime performance

I really want to use DateTime in most of my projects, especially when
I'm working with the likes of Class::DBI, to give the proper abstraction
for handling TIMESTAMP/DATETIME fields, as well as the free validation I
get from DateTime.

but DateTime's performance really bugs me. This is especially true when
I'm trying to use these modules in web applications.

As an example, Miyagawa-san had pointed out in his blog:

  http://blog.bulknews.net/mt/archives/000367.html

Here's my version of the above benchmark

  [timethese]
  Benchmark: timing 100000 iterations of datetime, posix...
    datetime: 139 wallclock secs (138.96 usr +  0.15 sys = 139.11 CPU) @
718.86/s (n=100000)
    posix:  0 wallclock secs ( 1.53 usr +  0.09 sys =  1.62 CPU) @
61728.40/s (n=100000)

  [cmpthese]
              Rate datetime    posix
  datetime   719/s       --     -99%
  posix    62112/s    8533%       --

Ouch.

I profiled this a long time ago, and Params::Validate seemed like a
problem. Anyway, here's fresh profile:

[EMAIL PROTECTED]:~$ ~/test/bin/dprofpp tmon.out
Total Elapsed Time = 11.44324 Seconds
  User+System Time = 11.42324 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 34.6   3.959  4.389  60277   0.0001 0.0001  Params::Validate::_validate
 12.3   1.410  7.609  20000   0.0001 0.0004  DateTime::new
 7.53   0.860  8.129  10000   0.0001 0.0008  DateTime::from_epoch
 6.92   0.790  0.940  60000   0.0000 0.0000
DateTime::TimeZone::_spans_binary_
                                             search
 6.57   0.750  1.780  10000   0.0001 0.0002  DateTime::strftime
 6.30   0.720  4.880  10000   0.0001 0.0005  DateTime::set
 6.04   0.690  1.640  20002   0.0000 0.0001  DateTime::TimeZone::new
 5.25   0.600  1.460 190000   0.0000 0.0000  DateTime::__ANON__
 4.81   0.550  0.630  30002   0.0000 0.0000
DateTime::_calc_local_components
 3.59   0.410  1.650  60000   0.0000 0.0000
DateTime::TimeZone::_span_for_date
                                             time
 3.15   0.360  1.770  30002   0.0000 0.0001  DateTime::_calc_local_rd
 3.06   0.350  1.150  30000   0.0000 0.0000
DateTime::_handle_offset_modifier
 2.36   0.270  0.280  20001   0.0000 0.0000  DateTime::Locale::load
 2.28   0.260  7.049  10000   0.0000 0.0007
DateTime::Format::Mail::format_dat
                                             etime
 1.84   0.210  0.210  60000   0.0000 0.0000  DateTime::TimeZone::max_span

Now let me try to profile this.

Ouch. Hmm, let me try this with PERL_NO_VALIDATION = 1

  [timethese]
  Benchmark: timing 100000 iterations of datetime, posix...
    datetime: 136 wallclock secs (135.06 usr +  0.12 sys = 135.18 CPU) @
739.75/s (n=100000)
    posix:  2 wallclock secs ( 1.48 usr +  0.10 sys =  1.58 CPU) @
63291.14/s (n=100000)

  [cmpthese]
              Rate datetime    posix
  datetime   740/s       --     -99%
  posix    63694/s    8513%       --

Argh. No luck.

I really really want to make it faster. I know that it's impossible to
match sprintf + localtime, but wouldn't it be nice if the difference was
an order of magnitude lower... ;)

So ... are we going to address this?

--d

Reply via email to