Unreasonable memory usage under linux with a simple loop

Discussion in 'Python' started by ming_cuhk, Jan 2, 2009.

  1. ming_cuhk

    ming_cuhk Guest

    Hi all, I'm new to here and python.
    When I tried the code below to test python's speed...
    I found that python use more than 1.5G memory to run this and cost
    several minutes.... And this happened only under my linux os. Both
    jython and python... Is there something wrong with python under linux
    or my code?
    Thanks!

    a = 0
    for i in range(100000000):
    a = a + 1
    print a
     
    ming_cuhk, Jan 2, 2009
    #1
    1. Advertising

  2. On Jan 2, 4:45 pm, ming_cuhk <> wrote:
    > Hi all, I'm new to here and python.
    > When I tried the code below to test python's speed...
    > I found that python use more than 1.5G memory to run this and cost
    > several minutes.... And this happened only under my linux os. Both
    > jython and python...  Is there something wrong with python under linux
    > or my code?
    > Thanks!
    >
    > a = 0
    > for i in range(100000000):
    >     a = a + 1
    > print a


    This is fixed in Python 3.0. In older Python versions, use
    xrange instead of range.
     
    Michele Simionato, Jan 2, 2009
    #2
    1. Advertising

  3. ming_cuhk

    ming_cuhk Guest

    On Jan 2, 11:49 pm, Michele Simionato <>
    wrote:
    > On Jan 2, 4:45 pm, ming_cuhk <> wrote:
    >
    > > Hi all, I'm new to here and python.
    > > When I tried the code below to test python's speed...
    > > I found that python use more than 1.5G memory to run this and cost
    > > several minutes.... And this happened only under my linux os. Both
    > > jython and python...  Is there something wrong with python under linux
    > > or my code?
    > > Thanks!

    >
    > > a = 0
    > > for i in range(100000000):
    > >     a = a + 1
    > > print a

    >
    > This is fixed in Python 3.0. In older Python versions, use
    > xrange instead of range.


    Thanks! But this isn't appear in MAC and Windows~?
     
    ming_cuhk, Jan 2, 2009
    #3
  4. On Jan 2, 4:50 pm, ming_cuhk <> wrote:
    > On Jan 2, 11:49 pm, Michele Simionato <>
    > wrote:
    >
    >
    >
    > > On Jan 2, 4:45 pm, ming_cuhk <> wrote:

    >
    > > > Hi all, I'm new to here and python.
    > > > When I tried the code below to test python's speed...
    > > > I found that python use more than 1.5G memory to run this and cost
    > > > several minutes.... And this happened only under my linux os. Both
    > > > jython and python...  Is there something wrong with python under linux
    > > > or my code?
    > > > Thanks!

    >
    > > > a = 0
    > > > for i in range(100000000):
    > > >     a = a + 1
    > > > print a

    >
    > > This is fixed in Python 3.0. In older Python versions, use
    > > xrange instead of range.

    >
    > Thanks! But this isn't appear in MAC and Windows~?


    It should happen on all platforms, since you are building
    a list with 100 millions of integers, which is quite large,
    especially if you are running on a 64 bit OS.
     
    Michele Simionato, Jan 2, 2009
    #4
  5. ming_cuhk

    ming_cuhk Guest

    On Jan 2, 11:52 pm, Michele Simionato <>
    wrote:
    > On Jan 2, 4:50 pm, ming_cuhk <> wrote:
    >
    >
    >
    > > On Jan 2, 11:49 pm, Michele Simionato <>
    > > wrote:

    >
    > > > On Jan 2, 4:45 pm, ming_cuhk <> wrote:

    >
    > > > > Hi all, I'm new to here and python.
    > > > > When I tried the code below to test python's speed...
    > > > > I found that python use more than 1.5G memory to run this and cost
    > > > > several minutes.... And this happened only under my linux os. Both
    > > > > jython and python...  Is there something wrong with python under linux
    > > > > or my code?
    > > > > Thanks!

    >
    > > > > a = 0
    > > > > for i in range(100000000):
    > > > >     a = a + 1
    > > > > print a

    >
    > > > This is fixed in Python 3.0. In older Python versions, use
    > > > xrange instead of range.

    >
    > > Thanks! But this isn't appear in MAC and Windows~?

    >
    > It should happen on all platforms, since you are building
    > a list with 100 millions of integers, which is quite large,
    > especially if you are running on a 64 bit OS.


    You are right...Thanks.... Since my MAC have too much RAM..I didn't
    notice it....
     
    ming_cuhk, Jan 2, 2009
    #5
    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. Replies:
    10
    Views:
    564
  2. Paul

    ridicuously unreasonable

    Paul, Feb 23, 2011, in forum: C++
    Replies:
    8
    Views:
    353
    Krice
    Feb 24, 2011
  3. Lynn McGuire
    Replies:
    40
    Views:
    708
  4. Isaac Won
    Replies:
    9
    Views:
    444
    Ulrich Eckhardt
    Mar 4, 2013
  5. Lynn McGuire

    "The Unreasonable Effectiveness of C"

    Lynn McGuire, May 30, 2014, in forum: C Programming
    Replies:
    11
    Views:
    124
Loading...

Share This Page