Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It works fast and is tiny.
I beg to differ. It is both slow and verbose. DateTime is 10 times faster, and Date::Calc is 700 times faster!
use strict; use warnings; use DateTime; use Date::Calc qw (Add_Delta_DHMS); use Benchmark qw(cmpthese); my $dt = DateTime->new( year => 2011, month => 1, day => 1, hour => 0, minute => 0, second => 0, ); my ($year, $month, $day, $hour, $min, $sec) = (2011, 1, 1, 0, 0, 0); cmpthese( -1, { 'DateTime' => sub { $dt->add(hours => 1, minutes => 2, seconds => 3); }, 'Date::Calc' => sub { ($year, $month, $day, $hour, $min, $sec) = Add_Delta_DHMS($year, $month, $day, $hour, $min, $sec, 0, 1, 2 +, 3); }, 'tsk1979' => sub { my $lat = 23.438; my $slon = 68.000; my $elon = 90.000; my $clon = $slon; my $incrlon = 0.01; my $time = time; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) + = localtime($time); my $incrtime = 1; my $printmon; my $printyear; while ($clon < $elon) { $printmon = $mon + 1; $printyear = $year + 1900; $clon = $clon + $incrlon; $time = $time + $incrtime; ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) += localtime($time); } }, } ); __END__ $ perl -l 883070.pl | tail -5 Rate tsk1979 DateTime Date::Calc tsk1979 339/s -- -90% -100% DateTime 3319/s 878% -- -100% Date::Calc 893673/s 263192% 26830% -- $
It is a good habit to Benchmark your code before making bold claims about its performance.
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

In reply to Re: Solution found! by andreas1234567
in thread Simple date and time manipulation by tsk1979

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2023-02-03 14:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (26 votes). Check out past polls.

    Notices?