chansen / p5-time-moment

Time::Moment represents an exact moment in time.
32 stars 8 forks source link

I want to know Time::Moment advantage compare with DateTime and Time::Piece #1

Open yuki-kimoto opened 10 years ago

yuki-kimoto commented 10 years ago

API look clean.

I want to know Time::Moment advantage compare with DateTime and Time::Piece.

chansen commented 10 years ago

The advantage is performance and memory usage. I intend to document this more properly, but here is the output of dev/bench.pl and dev/sizeof.pl.

$ perl -Mblib dev/bench.pl 
Benchmarking constructor: ->now()
                  Rate     DateTime  Time::Piece  localtime() Time::Moment
DateTime       27499/s           --         -88%         -97%         -98%
Time::Piece   223319/s         712%           --         -79%         -87%
localtime()  1065760/s        3776%         377%           --         -40%
Time::Moment 1779685/s        6372%         697%          67%           --

Benchmarking constructor: ->from_epoch()
                  Rate     DateTime  Time::Piece Time::Moment
DateTime       28203/s           --         -90%         -99%
Time::Piece   285870/s         914%           --         -91%
Time::Moment 3224391/s       11333%        1028%           --

Benchmarking accessor: ->year()
                  Rate     DateTime  Time::Piece Time::Moment
DateTime     3120158/s           --         -11%         -62%
Time::Piece  3525503/s          13%           --         -56%
Time::Moment 8104562/s         160%         130%           --

Benchmarking strftime: ->strftime('%FT%T')
                     Rate     DateTime POSIX::strftime  Time::Piece Time::Moment
DateTime          88662/s           --            -66%         -83%         -94%
POSIX::strftime  263045/s         197%              --         -49%         -83%
Time::Piece      514402/s         480%             96%           --         -67%
Time::Moment    1561555/s        1661%            494%         204%           --

Benchmarking parsing: '2013-12-24T12:34:56.123456+02:00'
                    Rate DT::F::ISO8601 DT::F::RFC3339   Time::Moment
DT::F::ISO8601    7097/s             --           -37%          -100%
DT::F::RFC3339   11202/s            58%             --          -100%
Time::Moment   2722665/s         38266%         24206%             --
$ perl -Mblib dev/sizeof.pl 
Time::Moment ............... :  104 B
Time::Piece ................ :  456 B
localtime() ................ :  296 B
DateTime ................... : 4019 B
DateTime w/o zone and locale : 2545 B
yuki-kimoto commented 10 years ago

Oh, very fast! Are there advantages in features?

chansen commented 10 years ago

Besides faster execution and heavily reduced memory usage:

Time::Moment is not feature complete:

If you have any features requests, please don't hesitate to submit them on this tracker.