Re: efficiency question

2006-07-01 Thread diffuser78
Thanks for this thing. http://www.python.org/doc/current/lib/module-dis.html made it more clear. Fredrik Lundh wrote: > David Harvey wrote: > > > Suppose I write > > > > if x in ("abc", "def", "xyz"): > > doStuff() > > > > elif x in ("pqr", "tuv", "123"): > > doOtherStuff() > > > > elif ... >

Re: efficiency question

2006-06-30 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > > when in doubt, ask the compiler: > > def code(x): > if x in ("abc", "def", "xyz"): > doStuff() > elif x in ("pqr", "tuv", "123"): > doOtherStuff() > > import dis > dis.dis(code) > > prints: > > 2 0 LOAD_FAST0 (x) >

Re: efficiency question

2006-06-30 Thread Scott David Daniels
David Harvey wrote: > if x in ("abc", "def", "xyz"): > doStuff() > elif x in ("pqr", "tuv", "123"): > doOtherStuff() > elif ... If the code really looks like this: # one-time-only code big_dispatch_table = {} for function, keys in [ (doStuff,

Re: efficiency question

2006-06-30 Thread diffuser78
can you please explain how to read these output...I mean how to understand them. A quick glance tells you that the latter approach has less number of instructions and thats why its better. Any more insight would help a lot. MTD wrote: > For the sake of comparison: > > >>> def cod(x): > ... tuppl

Re: efficiency question

2006-06-30 Thread diffuser78
So nice to know this that you can compare your own code using this methodology. I was completely unaware of this. Thank you so much. Fredrik Lundh wrote: > David Harvey wrote: > > > Suppose I write > > > > if x in ("abc", "def", "xyz"): > > doStuff() > > > > elif x in ("pqr", "tuv", "123"): > >

Re: efficiency question

2006-06-30 Thread David Harvey
Fredrik Lundh wrote: > when in doubt, ask the compiler: MTD wrote: > >>> dis.dis(cod) Thanks so much guys! Python just gets cooler every day! David -- http://mail.python.org/mailman/listinfo/python-list

Re: efficiency question

2006-06-30 Thread MTD
For the sake of comparison: >>> def cod(x): ... tupple1 = ("abc", "def", "xyz") ... tupple2 = ("pqr", "tuv", "123") ... if x in tupple1: ... doStuff() ... elif x in tupple2: ... doOtherStuff() ... >>> dis.dis(cod) 2 0 LOAD_CONST 7 (

Re: efficiency question

2006-06-30 Thread Fredrik Lundh
David Harvey wrote: > Suppose I write > > if x in ("abc", "def", "xyz"): > doStuff() > > elif x in ("pqr", "tuv", "123"): > doOtherStuff() > > elif ... > When is python building the tuples? Does it need to build the tuple > every time it comes through this code? Or does it somehow recognise > that

efficiency question

2006-06-30 Thread David Harvey
Hi, Suppose I write if x in ("abc", "def", "xyz"): doStuff() elif x in ("pqr", "tuv", "123"): doOtherStuff() elif ... etc. When is python building the tuples? Does it need to build the tuple every time it comes through this code? Or do