frozenset question

George Sakkis gsakkis at rutgers.edu
Wed Jul 6 20:02:33 EDT 2005


"Steven D'Aprano" <steve at REMOVETHIScyber.com.au> wrote:

> On Wed, 06 Jul 2005 10:15:31 -0700, George Sakkis wrote:
>
> > Well, they *may* be interchangable under some conditions, and that was
> > the OP's point you apparently missed.
>
> I didn't miss anything of the sort. That's why I spent 15 minutes actually
> producing test cases to MEASURE if there was any detectable speed
> differences between accessing set and frozenset instead of wasting time
> worrying about "tiny" differences in performance that are almost certainly
> lost in the noise in real code.
>
> If, over a thousand runs of the program, you save a millisecond of time in
> total, but it costs you two seconds to type the comment in the code
> explaining why you used frozenset instead of the more natural set, then
> your "optimization" is counter-productive. Even just considering the
> question is a waste of valuable developer time! THAT is the lesson of
> premature optimization: don't even THINK about optimizing code until you
> have it WORKING and you have MEASURED that it is too slow.

I fully agree with your last sentence, first profile and then consider
if it's worth optimizing. Still, you either missed the point again or
you are arguing for the sake of the argument. Neither me nor the OP
claimed that it's worthwhile saving a millisecond or two. The OP hadn't
done the timing measurements you did, so he didn't know in advance if
the difference is 1 millisecond or 500. After you replied with evidence
that it's not worth it, he made clear that he was just enquiring, not
optimizing prematurely as you took for granted and ranted against it
from the beginning.

Hope it's clear now,

George




More information about the Python-list mailing list