Hi,
Are there any benefits in using a frozenset over a set, other than it
being immutable?
Will McGugan
-- http://www.willmcgugan.com
"".join({'*':'@ ','^':'.'}.get( c,0) or chr(97+(ord(c)-84)%26) for c in
"jvyy*jvyyzptht na^pbz")
Jul 21 '05
10 4051
"Steven D'Aprano" <st***@REMOVETH IScyber.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 "optimizati on" 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefan Behnel |
last post by:
Hi!
frozenset() doesn't behave as the other immutable empty data types in 2.4:
..>>> '' is ''
True
..>>> () is ()
True
..>>> frozenset() is frozenset()
False
|
by: Jacob Page |
last post by:
I have released interval-0.2.1 at
http://members.cox.net/apoco/interval/. IntervalSet and
FrozenIntervalSet objects are now (as far as I can tell) functionality
equivalent to set and frozenset objects, except they can contain
intervals as well as discrete values.
Though I have my own unit tests for verifying this claim, I'd like to
run my code through actual set and frozenset unit tests. Does any such
code exist? Is it in pure...
|
by: Mark E. Fenner |
last post by:
Hello all,
I was migrating some code from sets.ImmutableSet to frozenset and noticed
the following:
******code********
#!/usr/bin/env python
from sets import ImmutableSet
|
by: Christoph Zwerschke |
last post by:
Sometimes I find myself stumbling over Python issues which have to do
with what I perceive as a lack of orthogonality.
For instance, I just wanted to use the index() method on a tuple which
does not work. It only works on lists and strings, for no obvious
reason. Why not on all sequence types?
Or, another example, the index() method has start and end parameters for
lists and strings. The count() method also has start and end parameters...
|
by: Gregory Guthrie |
last post by:
I am comparing Python to a few other scripting languages, and used a simple
anagrams program as a sample.
I was surprised ast a few python features that did not work as I would
expect/wish; which caused less compact/expressive program styles that I
wanted - reverting to a FORTRAN like series of assignments.
For example,
- why is len() not a member function of strings? Instead one says len(w).
| |
by: John Salerno |
last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part,
but it does in the second? Is the first statement something different?
False
print 'hi'
hi
Thanks.
|
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= |
last post by:
s0 = set()
In that case, there is always a trivial answer. As I can use any
function which takes and returns sets, and as I shall come up with
a function that returns s0, I just use the following function
def f(s):
return s0
To compute s0, just invoke f with any other of the sets, and you
|
by: srinivasan srinivas |
last post by:
Hi,
I am getting an error while executing the following snippet. If i comment out method __repr__ , it works fine.
class fs(frozenset):
def __new__(cls, *data):
data = sorted(data)
self = frozenset.__new__(cls, data)
self.__data = data
return self
|
by: Terry Reedy |
last post by:
srinivasan srinivas wrote:
When posting problems like this, please include the Python version.
If you ran this with 2.6, please run the following:
x = frozenset('abc')
y = frozenset('bcd')
z = x.difference(y)
print(id(x) != id(z))
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |