Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > why does dead code costs time?

Reply
Thread Tools

why does dead code costs time?

 
 
Bruno Dupuis
Guest
Posts: n/a
 
      12-05-2012
I added a patch on the issue tracker. It solves the bug for short
(<32700 bytes) functions

ref : http://bugs.python.org/file28217/16619-1.patch

--
Bruno Dupuis
 
Reply With Quote
 
 
 
 
Ramchandra Apte
Guest
Posts: n/a
 
      12-09-2012
On Wednesday, 5 December 2012 22:10:51 UTC+5:30, Bruno Dupuis wrote:
> On Wed, Dec 05, 2012 at 04:15:59PM +0000, Neil Cerutti wrote:
>
> > On 2012-12-05, Bruno Dupuis <(E-Mail Removed)> wrote:

>
> > > Hi,

>
> > >

>
> > > I'm interested in compilers optimizations, so I study python

>
> > > compilation process

>
> > >

>
> > > I ran that script:

>
> > >

>
> > > import timeit

>
> > >

>
> > > def f(x):

>
> > > return None

>
> > >

>
> > > def g(x):

>
> > > return None

>
> > > print(x)

>
> > >

>
> > > number = 10000

>
> > >

>
> > > print(timeit.timeit('f(1)',setup="from __main__ import f", number=number))

>
> > > print(timeit.timeit('g(1)',setup="from __main__ import g", number=number))

>
> > >

>
> > > print(dis.dis(f))

>
> > > print(dis.dis(g))

>
> > >

>
> > > It gives this output:

>
> > >

>
> > > 0.003460251959040761

>
> > > 0.004164454061537981

>
> > > 17 0 LOAD_CONST 0 (None)

>
> > > 3 RETURN_VALUE

>
> > > None

>
> > > 20 0 LOAD_GLOBAL 0 (None)

>
> > > 3 RETURN_VALUE

>
> > >

>
> > > 21 4 LOAD_GLOBAL 1 (print)

>
> > > 7 LOAD_FAST 0 (x)

>
> > > 10 CALL_FUNCTION 1 (1 positional, 0 keyword pair)

>
> > > 13 POP_TOP

>
> > > None

>
> > >

>
> > > I do not understand why the dead code `print(x)` takes time (~20% in

>
> > > that case). As we see in the opcode, a call to g(1) returns immediately, so

>
> > > there should be no delay at all. Where am i wrong?

>
> > >

>
> > > mmhh... it comes to me now that the gap must be in function loading time...

>
> > > I'll check ceval.c

>
> > >

>
> > > However, isn't there a room for a slight optim here? (in this case, the

>
> > > dead code is obvious, but it may be hidden by complex loops and

>
> > > conditions)

>
> >

>
> > Maybe it's the difference between LOAD_CONST and LOAD_GLOBAL. We

>
> > can wonder why g uses the latter.

>
>
>
> Good point! I didn't even noticed that. It's weird... Maybe the
>
> difference comes from a peehole optim on f which is not possible on g as
>
> g is to complex.
>
>
>
> >

>
> > --

>
> > Neil Cerutti

>
> > --

>
> > http://mail.python.org/mailman/listinfo/python-list

>
>
>
> --
>
> Bruno Dupuis


peehole haha
 
Reply With Quote
 
 
 
 
Mark Lawrence
Guest
Posts: n/a
 
      12-09-2012
On 09/12/2012 14:11, Ramchandra Apte wrote:
>
> peehole haha
>


Double spaced crap from you again not so haha.

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      12-13-2012
On Sunday, 9 December 2012 22:17:09 UTC+5:30, Mark Lawrence wrote:
> On 09/12/2012 14:11, Ramchandra Apte wrote:
>
> >

>
> > peehole haha

>
> >

>
> Double spaced crap from you again not so haha.
>
> --
>
> Cheers.
>
> Mark Lawrence.


haha. What does "Cheers" mean?
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      12-13-2012
On Sunday, 9 December 2012 22:17:09 UTC+5:30, Mark Lawrence wrote:
> On 09/12/2012 14:11, Ramchandra Apte wrote:
>
> >

>
> > peehole haha

>
> >

>
> Double spaced crap from you again not so haha.
>
> --
>
> Cheers.
>
> Mark Lawrence.


haha. What does "Cheers" mean?
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      12-13-2012
On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:

>> Cheers.
>>
>> Mark Lawrence.

>
> haha. What does "Cheers" mean?


It is an exclamation expressing good wishes. In particular, good wishes
before drinking. Think of it as a variation on:

"Good health to you"
"Best wishes"
"Sincerest regards"

only less formal.


Does the Internet not work where you are? Googling for "define:cheers" or
"definition cheers" should have answered that question.



--
Steven
 
Reply With Quote
 
rusi
Guest
Posts: n/a
 
      12-13-2012
On Dec 13, 11:01*am, Steven D'Aprano <steve
(E-Mail Removed)> wrote:
> On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:
> >> Cheers.

>
> >> Mark Lawrence.

>
> > haha. What does "Cheers" mean?

>
> It is an exclamation expressing good wishes. In particular, good wishes
> before drinking. Think of it as a variation on:
>
> "Good health to you"
> "Best wishes"
> "Sincerest regards"
>
> only less formal.
>
> Does the Internet not work where you are? Googling for "define:cheers" or
> "definition cheers" should have answered that question.
>
> --
> Steven


One line above the "cheers" (with a double-space <wink>) we find:

> Double spaced crap from you again not so haha.


Do you find the sentiment expressed therein consistent with any of
your three meanings?

 
Reply With Quote
 
Cameron Simpson
Guest
Posts: n/a
 
      12-13-2012
On 12Dec2012 22:27, rusi <(E-Mail Removed)> wrote:
| On Dec 13, 11:01*am, Steven D'Aprano <steve
| (E-Mail Removed)> wrote:
| > On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:
| > >> Cheers.
| > >> Mark Lawrence.
| >
| > > haha. What does "Cheers" mean?
| >
| > It is an exclamation expressing good wishes. In particular, good wishes
| > before drinking. [...]
|
| One line above the "cheers" (with a double-space <wink>) we find:
|
| > Double spaced crap from you again not so haha.
|
| Do you find the sentiment expressed therein consistent with any of
| your three meanings?

Nope. But they're separate sentiments (weasel words

I tend to end messages with "Cheers" myself. Though I also tend to strip
it out if I am being annoyed. As you say, it is inconsistent.

Cheers,
--
Cameron Simpson <(E-Mail Removed)>

It looked good-natured, she thought; Still it had very long claws and a
great many teeth, so she felt it ought to be treated with respect.
 
Reply With Quote
 
rusi
Guest
Posts: n/a
 
      12-13-2012
On Dec 13, 11:51*am, Cameron Simpson <(E-Mail Removed)> wrote:
> It looked good-natured, she thought; *Still it had very long claws and a
> great many teeth, so she felt it ought to be treated with respect.


heh!

If only we could respect without such coercion(s)
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      12-13-2012
On Thu, Dec 13, 2012 at 5:59 PM, rusi <(E-Mail Removed)> wrote:
> On Dec 13, 11:51 am, Cameron Simpson <(E-Mail Removed)> wrote:
>> It looked good-natured, she thought; Still it had very long claws and a
>> great many teeth, so she felt it ought to be treated with respect.

>
> heh!
>
> If only we could respect without such coercion(s)


Even if you don't respect his claws and teeth, you should respect the
fact that, as he says, "we're all mad here"...

But this is quite off topic, both off the thread's subject line and
the list's purpose.

ChrisA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
Dead TCP/IP Stack = DEAD VISTA !! Skybuck Flying Windows 64bit 15 09-23-2007 07:54 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Dead... the damn thing's dead... David Dean Computer Support 9 01-30-2004 02:54 AM



Advertisments