frozenset question

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jul 6 17:48:19 CEST 2005


On Wed, 06 Jul 2005 14:25:30 +0100, Will McGugan wrote:

>> But if you are just trying to optimize for the sake of optimization,
>> that's a terrible idea. Get your program working first. Then when it
>> works, measure how fast it runs. If, and ONLY if, it is too slow, 
>> identify the parts of the program that make it too slow. That means
>> profiling and timing. Then optimize those parts, and nothing else.
>> 
>> Otherwise, you will be like the car designer trying to speed up his sports
>> cars by making the seatbelts aerodynamic.
> 
> No need for the 'premature optimization is the root of all evil' speech. 
> I'm not trying to optimize anything - just enquiring about the nature of 
> frozenset. If typing 'frozenset' over 'set' gave me a saving in time or 
> memory (even if tiny) I would favour immutable sets, where appropriate.

Well, obviously the "premature optimization" speech just went in one ear
and out the other. "Saving in time or memory" is what optimization is
about. What did you think optimization means?

set and frozenset have different functionality (one is mutable, the other
is not) and use cases (you use one where you need to dynamically add and
remove items from a set, and the other where you need to use a set as a
key in a dictionary). In most cases, they aren't interchangable. While
you're spending time worrying about shaving a thousandth of a millisecond
off a program that takes five seconds to run, I'll get on with development
using the right object for the functionality needed.



-- 
Steven.




More information about the Python-list mailing list