The code I pointed to isn't a direct alternative to yours as it starts with the timestamps in their 8-byte binary form as you receive them from OS calls like GetFileTime(), GetThreadTimes() etc. You appear to be starting with them in ascii-ized form which means you don't need to unpack the binary representation.
Still, re-calculating a constant each time you use it seemed a little unnecessary. Especially as once you've subtracted the constant difference betweeen 1/1/1601 and 1/1/1970, the numbers fall into a range that is easily handled without resorting to Math::BigInt.
The concept of slow really is an odd thing these days, with RAM capacities and CPU speeds what they are, what's the big deal,
That's exactly the attitude that led to the concept of 7-litre (500ci) shopping cars in the early '70s. Oil was $3/barrel, petrol 25cents a gallon. Iron was heavy, but cheap. Then things changed. Oil quadrupled in price over night--and stayed there. The world panicked. Over the next few years the price rose again to the unimaginable price of $38/barrel.
Now look at us. The price of oil is (or was recently) $55/barrel. Depending upon which bunch of scientists or lobbyists you choose to believe, we're all about to bake, freeze or drown. Probably all three.
No, I don't expect the price of silicon to quadruple, but making chips costs energy. Using chips costs energy(*) and energy isn't going to get cheaper any time soon. If ever. Using more and Moore powerful chips, and Moore and more of them, as an expedient solution to writing code that is unnecessarilly wasteful. Ie. 50 times slower:
#! perl -slw use strict; use POSIX qw[ strftime ]; use Math::BigInt; use Date::Calc qw/Add_Delta_Days/; use Benchmark qw[ cmpthese ]; sub holli { return POSIX::strftime( "%Y-%m-%d", localtime( ( $_[0] / 10000000 ) - 11644473600 ) ); } sub yours { my $loginTime = Math::BigInt->new( $_[ 0 ] ); $loginTime = $loginTime / (60 * 10000000 ); # 60 seconds in a min +ute! $loginTime = $loginTime / 1440; my ($year,$month,$day) = Add_Delta_Days( 1601, 1, 1, $loginTime ); return "$year-$month-$day\n"; } our $lastLoginTime = '127912653523035916'; cmpthese -1, { yours => q[ my $dateStr = yours( $lastLoginTime ); ], holli => q[ my $dateStr = holli( $lastLoginTime ); ], } __END__ holli: 2006-05-05 yours: 2006-5-5 c:\test>junk8 Rate yours holli yours 3150/s -- -98% holli 161606/s 5030% --
Just doesn't make sense. Moore is going the way of $3/barrel oil any day now.
For this one routine, for one date, it's neither here nor there. But when you start processing a few hundred users on each of a few tens or hundreds of servers, it will add up. If every other routine you write is equally as inefficient, then you (or those that make use of your code), will soon need a bigger machine, or a cluster of them. If you or your customers are Google-like, then you need a few thousand extra, more powerful machines. And so it goes.
When someone knocks on your front door, do you go to the back door and walk all the way around to the front to see who it is? Efficiency is simply logical.
(*)Update: For those that consider that worrying about the power consumption of servers is stupid. Computer servers are estimated to have consumed 1.2% of all the energy used in the USA during 2006.
In reply to Re^3: Calculating lastLoginTimeStamp from Active Directory
by BrowserUk
in thread Calculating lastLoginTimeStamp from Active Directory
by waxhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |