[Python-ideas] A conditional "for" statement

Michael S. Gilbert michael.s.gilbert at gmail.com
Fri Apr 24 01:40:16 CEST 2009


On Thu, 23 Apr 2009 19:09:14 -0400, Mike Meyer wrote:
> If you believe this is still true (though as has been pointed out,
> this idea has already been considered and rejected), show us the
> timings. In particular, with a range of different values for the
> percentage of excluded elements: say 0, 10, 50, 90 and 100?

Ok, I'll admit when I'm wrong.  It actually takes longer to use the
list comprehension (for all exclusion percentages), which, for me at
least, is completely unintuitive.  For 1 million samples:

excluded: 0%, comprehension time: 0.840000
excluded: 0%, if time: 0.530000
excluded: 10%, comprehension time: 0.770000
excluded: 10%, if time: 0.520000
excluded: 20%, comprehension time: 0.710000
excluded: 20%, if time: 0.490000
excluded: 30%, comprehension time: 0.670000
excluded: 30%, if time: 0.460000
excluded: 40%, comprehension time: 0.610000
excluded: 40%, if time: 0.450000
excluded: 50%, comprehension time: 0.560000
excluded: 50%, if time: 0.420000
excluded: 60%, comprehension time: 0.510000
excluded: 60%, if time: 0.400000
excluded: 70%, comprehension time: 0.450000
excluded: 70%, if time: 0.380000
excluded: 80%, comprehension time: 0.410000
excluded: 80%, if time: 0.350000
excluded: 90%, comprehension time: 0.360000
excluded: 90%, if time: 0.330000
excluded: 100%, comprehension time: 0.310000
excluded: 100%, if time: 0.300000

I hereby accept the rejection of this idea since it makes sense neither
from a syntax nor efficiency point of view.

Best Regards,
Mike



More information about the Python-ideas mailing list