What is the performace of PHPs strtotime()?

OnlnPharmrx

New Member
I am doing some large timestamp-list iterations: Putting them in tables with date-ranges, and grouping them by ranges. In order to do that, I found \[code\]strtotime()\[/code\] a very helpfull function, but I am worried about its performance.For example, a function that loops over a list of weeks (say, week 49 to 05) and has to decide the beginning of the week and the timestamp at the end of that week. A usefull way to do that, would be:\[code\]foreach ($this->weeks($first, $amount) as $starts_at) { $ends_at = strtotime('+1 week', $starts_at); $groups[$week_key] = $this->slice($timestamps, $starts_at, $ends_at);}//$this->weeks returns a list of timestamps at which each week starts.//$this->slice is a simple helper that returns only the timestamps within a range, from a list of timestamps. \[/code\]Instead of \[code\]strtotime()\[/code\], I could, potentially, find out the amount of seconds between begin and end of the week, 99% of the times that would be \[code\]24 * 60 * 60 * 7\[/code\]. But in these rare cases where there is a DST-switch, that 24 should either be 23 or 25. Code to sort that out, will probably be a lot slower then \[code\]strtotime()\[/code\], not?I use the same patterns for ranges of years, months (months, being very inconsistent!), days and hours. Only with hours would I suspect simply adding \[code\]3600\[/code\] to the timestamp is faster. Any other gotcha's? Are there ways (that do not depend on PHP5.3!) that offer better routes for consistent, DST and leap-year safe dateranges?
 
Back
Top