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 8633611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:31:16+00:00 2026-06-12T09:31:16+00:00

I want to know how long it takes since I execute the code to

  • 0

I want to know how long it takes since I execute the code to start the timer and then the one to finish. For example, this is something I’d be looking for:

import timerlib
import urllib2

timer = timerlib.timer()

print 'Starting download now!'
timer.start()

urllib2.urlopen('http://some.site.com/100mb')

timer.stop()
print 'Downloaded 100mb in ' + str(timer.collectedtime()) + '!'

And it would output something like: Downloaded 100mb in 5m31s!

How can I do this?

  • 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-12T09:31:17+00:00Added an answer on June 12, 2026 at 9:31 am

    If you’re just printing out a time for the convenience of the end user, not for profiling purposes, you don’t need anything fancy; time.time returns timestamps you can do arithmetic on and print (in fact, just floating-point seconds):

    import time
    t0 = time.time()
    print 'Starting download now!'
    urllib2.urlopen('http://some.site.com/100mb')
    t = time.time()
    print 'Downloaded 100mb in ' + str(t - t0) + '!'
    

    But if you’re looking for profiling, you definitely want to use timeit:

    import timeit
    timeit.timeit("urllib2.urlopen('http://some.site.com/100mb')", 
                  setup="import urllib2", 
                  number=1)
    

    As you can see, this is not nearly as clean and simple, or as flexible. But the timeit library takes care of all kinds of details that novices never think of, and experienced developers still get wrong.

    (Of course in real life, you never want to profile anything based on just one run, so you shouldn’t be passing number=1. That was just to demonstrate the closest equivalent.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if this web app are using long polling or anything
I want to know how long a command takes to run. At the moment
I want to know how long it takes for my AJAX call to drop
Long-time joelonsoftware follower, 1st-time stackoverflow poster. I want to know how safely I can
i want to know how i can rewrite this SQL into a single select
I want to time how long it takes the server to build a MediaWiki
I know this could be a subjective question, but I want to know your
I have done something like this a long time ago where I captured the
How long is a single spin in c#? What I want to know is
i want know how i can manage multiple twitter account on iOS in my

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.