[pypy-issue] [issue900] Using cProfile on Windows generates negative tottime values

Garen Parham tracker at bugs.pypy.org
Sun Oct 9 10:29:15 CEST 2011


New submission from Garen Parham <garen.p at gmail.com>:

PS C:\Users\Garen\dev\pyfun> pypy-c -m cProfile .\primes_inf_gen.py 10000000
         10664601 function calls in 20.204 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   20.204   20.204 primes_inf_gen.py:1(<module>)
        1    1.111    1.111   20.204   20.204 primes_inf_gen.py:21(primes_up_to)
   664580    0.263    0.000    0.263    0.000 primes_inf_gen.py:22(<lambda>)
   664580 -5015.618   -0.008   18.830    0.000 primes_inf_gen.py:3(primes)
        1    0.000    0.000    0.000    0.000 {method 'disable' of 
'_lsprof.Profiler' objects}
  9335438 5034.447    0.001 5034.447    0.001 {method 'pop' of 'dict' objects}

Issue doesn't occur with just '-m profile':
PS C:\Users\Garen\dev\pyfun> pypy-c -m profile .\primes_inf_gen.py 10000000
         10664602 function calls in 14.609 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  9335438    1.789    0.000    1.789    0.000 :0(pop)
        1    0.001    0.001    0.001    0.001 :0(setprofile)
        1    0.000    0.000   14.607   14.607 primes_inf_gen.py:1(<module>)
        1    2.153    2.153   14.607   14.607 primes_inf_gen.py:21(primes_up_to)
   664580    0.673    0.000    0.673    0.000 primes_inf_gen.py:22(<lambda>)
   664580    9.992    0.000   11.781    0.000 primes_inf_gen.py:3(primes)
        1    0.000    0.000   14.609   14.609 profile:0(<code object <module>, 
file '.\primes_inf_gen.py', line 1>)
        0    0.000             0.000          profile:0(profiler)

Using Windows 7 x64, FWIW.

----------
files: primes_inf_gen.py
messages: 3276
nosy: Garen, pypy-issue
priority: bug
status: unread
title: Using cProfile on Windows generates negative tottime values

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue900>
________________________________________
-------------- next part --------------
import sys
import itertools 
def primes():
    composites = {} # A mapping from composite numbers to the smallest prime
                    # that is a factor of it (its witness).
    n = 2 # The current number being considered as a prime.
    while True:
        if n not in composites:
            yield n # Not a composite, therefore prime.
            composites[n**2] = n # The next unseen composite number is n squared.
        else:
            # n is composite. Find the next unseen composite number with the
            # same witness as n.
            witness = composites.pop(n)
            next = n + witness
            while next in composites:
                next += witness
            composites[next] = witness
        n += 1
 
def primes_up_to(limit):
    return list(itertools.takewhile(lambda p: p <= limit, primes()))

if __name__ == '__main__':
    primes_up_to(int(sys.argv[1]))
    


More information about the pypy-issue mailing list