Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33478 > unrolled thread

Re: module trace and counts

Started byDave Angel <d@davea.name>
First post2012-11-17 13:37 -0500
Last post2012-11-17 21:54 -0500
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: module trace and counts Dave Angel <d@davea.name> - 2012-11-17 13:37 -0500
    Re: module trace and counts Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-18 01:30 +0000
      Re: module trace and counts Dave Angel <d@davea.name> - 2012-11-17 21:54 -0500

#33478 — Re: module trace and counts

FromDave Angel <d@davea.name>
Date2012-11-17 13:37 -0500
SubjectRe: module trace and counts
Message-ID<mailman.3777.1353177465.27098.python-list@python.org>
On 11/17/2012 12:25 PM, rh wrote:
> Is it for or range that is executed 8000 times when I
> for i in range(3,8000,2):
Nothing is executed 8000 times.  I figure it at 3998 times.  Anyway,
neither the for nor the range is executed multiple times.  Deciphering
this depends on whether this is Python 2.x or Python 3.x.

If Python 2.x, range returns a list of 3998 items, and that is iterated
over.
If Python 3.x, range returns a range object, which has an __iter__()
special method.  That method gets called 3999 times, and the last time
it throws an exception to end the loop.

>
> Maybe the for and the range contributes to that total.
>
> Can anyone recommend their favorite trace or profile type tool that
> spits out an html page? I like trace because I don't have to insert my
> program into it but would like a html page too.
>


-- 

DaveA

[toc] | [next] | [standalone]


#33489

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-11-18 01:30 +0000
Message-ID<50a83a40$0$29978$c3e8da3$5496439d@news.astraweb.com>
In reply to#33478
On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:

> On 11/17/2012 12:25 PM, rh wrote:
>> Is it for or range that is executed 8000 times when I for i in
>> range(3,8000,2):
> Nothing is executed 8000 times.  I figure it at 3998 times.

Off by one.

py> len(range(3, 8000, 2))
3999


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#33490

FromDave Angel <d@davea.name>
Date2012-11-17 21:54 -0500
Message-ID<mailman.3784.1353207300.27098.python-list@python.org>
In reply to#33489
On 11/17/2012 08:30 PM, Steven D'Aprano wrote:
> On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:
>
>> On 11/17/2012 12:25 PM, rh wrote:
>>> Is it for or range that is executed 8000 times when I for i in
>>> range(3,8000,2):
>> Nothing is executed 8000 times.  I figure it at 3998 times.
> Off by one.
>
> py> len(range(3, 8000, 2))
> 3999
>
>
I should have actually let Python figure it.  Instead I knocked off one
because the interval is half-open, and another because it starts at 3. 
Then I checked it by subtracting the first from the last and dividing by
2  ( (7999-3)/2 ), but then made the stupid mistake of not adding one
because my interval WAS closed.



-- 

DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web