|P is for Practical|
Loops loosing Performanceby PerlingTheUK (Hermit)
|on Jun 09, 2005 at 23:07 UTC||Need Help??|
PerlingTheUK has asked for the
wisdom of the Perl Monks concerning the following question:
Dear Monks, I have currently a set of values for weekdays, that is stored as integer. To clarify here are example binary values:
Mon = 0b0000001 = 1
Tue = 0b0000010 = 2
Mon to Fri = 0b0011111 = 31
Sat to Sun = 0b1100000 = 96
I need to know how many days of running two sets of data have in common. This is a simple task, however I got stuck in a vicious circle between simplicity and performance. I st up five test functions and compared their speed. It did not surprise me much, that the fastes way is a bitwise evaluation. But if I ran through all days with a loop, the function is a lot slower. Can anyone suggest a better way to approach this? Please find the current code below.
The performance lost by the loop is quite steep, but the code nicer.