Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8380911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:34:40+00:00 2026-06-09T16:34:40+00:00

I wrote the following script Basically, I’m just learning Python for Machine Learning and

  • 0

I wrote the following script

Basically, I’m just learning Python for Machine Learning and wanted to check how really computationally intensive tasks would perform. I observe that for 10**8 iterations, Python takes up a lot of RAM (around 3.8 GB) and also a lot of CPU time (just froze my system)

I want to know if there is any way to limit the time/memory consumption either through code or some global settings

Script –

initial_start = time.clock()
for i in range(9):
 start = time.clock()
 for j in range(10**i):
  pass
 stop = time.clock()
 print 'Looping exp(',i,') times takes', stop - start, 'seconds'
final_stop = time.clock()
print 'Overall program time is',final_stop - initial_start,'seconds'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:34:41+00:00Added an answer on June 9, 2026 at 4:34 pm

    look at this question: How to limit the heap size?

    To address your script, the timeit module measures the time it takes to perform an action more accurately

    >>> import timeit
    >>> for i in range(9):
    ...     print timeit.timeit(stmt='pass', number=10**i)
    ...
    0.0
    0.0
    0.0
    0.0
    0.0
    0.015625
    0.0625
    0.468752861023
    2.98439407349
    

    Your example is taking most of its time dealing with the gigantic lists of numbers you’re putting it memory. xrange instead of range will help fix that issue but you’re still using a terrible benchmark. the loop is going to execute over and over and not actually do anything, so the cpu is busy checking the condition and entering the loop.

    As you can see, creating these lists is taking the majority of the time here

    >>> timeit.timeit(stmt='range(10**7)', number=1)
    0.71875405311584473
    >>> timeit.timeit(stmt='for i in range(10**7): pass', number=1)
    1.093757152557373
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following script, which generates a SyntaxError : #!/usr/bin/python print Enter the
I wrote the following Nant script on my Vista dev machine and was pleased
I have an interesting problem. I wrote the following perl script to recursively loop
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I'm trying to copy files inside a Python script using the following code: inf,outf
I wrote the following Perl script (below) in order to create simple XML file.
I wrote the following pre-commit script for SVN to validate that a user has
I wrote a python script that rotates an image 90 degrees. I am including
I wrote the following script that works fine in my SQL Server 2008 developer
I wrote the following script to avoid exposing the protected files to users logged

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.