can anybody explain this range() speedup (with psyco)

Discussion in 'Python' started by thattommyhallll@gmail.com, Jul 28, 2006.

  1. Guest

    i am doing the problems at
    http://www.mathschallenge.net/index.php?section=project
    one problem involved finding factors, i used

    def divisors(n):
    divisors = set([1])
    for i in range(1, math.ceil(n ** 0.5)+1):
    if n % i == 0:
    divisors.add(i)
    divisors.add(n/i)
    return divisors

    and it took 16s to solve the task, not too bad.
    using psyco brought this down to 5s, nice
    i tried it in ironpython and got an error in the range() function,
    which i corrected by changing it to
    for i in range(1, int(n ** 0.5)+1):
    and ironpython took 9s.

    when i reran this in psyco, i got a 2x speed improvement (down to 2s)

    ive just noticed after leaving idle that there is a depreciation
    warning about non-int args to range(), but my question is, why can me
    bunging a int( ) in there be faster than whatever python does to
    non-int args?

    where can i get info on performance of algorithms, ideally with ref to
    python, etc?
    ive got Python Programming:An intro to computer science, but it seems a
    bit basic. anybody know of good unis/colleges using python on their com
    sci courses?

    its nice to look at the forums on the mathschallenge page and see how
    python is the sweet spot between concise/readable. ive been tempted by
    ruby but it does not scan nearly as well.
     
    , Jul 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Tmljaw==?=
    Replies:
    2
    Views:
    448
    =?Utf-8?B?Tmljaw==?=
    Jan 11, 2006
  2. Replies:
    2
    Views:
    342
    VisionSet
    May 24, 2006
  3. Replies:
    1
    Views:
    298
    Victor Bazarov
    Oct 22, 2007
  4. Replies:
    13
    Views:
    524
    James Kanze
    Nov 17, 2008
  5. roohbir

    Can anybody explain this code pls?

    roohbir, Oct 23, 2006, in forum: Javascript
    Replies:
    2
    Views:
    113
    Evertjan.
    Oct 23, 2006
Loading...

Share This Page