Efficient counting of results

MRAB python at mrabarnett.plus.com
Fri Oct 20 14:39:35 EDT 2017


On 2017-10-20 18:05, Israel Brewster wrote:[snip]
> In a sense, in that it supports my initial approach.
> 
> As Stefan Ram pointed out, there is nothing wrong with the solution I have: simply using if statements around the calculated lateness of t1 and t2 to increment the appropriate counters. I was just thinking there might be tools to make the job easier/cleaner/more efficient. From the responses I have gotten, it would seem that that is likely not the case, so I'll just say "thank you all for your time", and let the matter rest.
> 
It occurred to me that it might be more efficient to start with the 
year-to-date first.

The reasoning is that over time the number of old entries will increase, 
so if you see that a timestamp isn't in this period_of_time, then it's 
not in any smaller_period_of_time either, so you can short-circuit.

Compare doing these for an old entry:

Day first: this day? no; this week? no; this month? no; this year? no.

Year first: this year? no.



More information about the Python-list mailing list