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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:25:09+00:00 2026-06-18T04:25:09+00:00

Is there any significant difference between: from time import time start = time() #

  • 0

Is there any significant difference between:

from time import time
start = time()
# some process
print time() - start

and:

from timeit import timeit
def my_funct():
    # some process
print timeit(my_funct, number=1)

For an example, I’ll use Project Euler 1 (because it’s really easy to understand/solve)

def pE1test1(): # using time()
    from time import time
    start = time()
    print sum([n for n in range(1, 1000) if n%3==0 or n%5==0])
    print time() - start

def pE1test2(): # using timeit
    print sum([n for n in range(1, 1000) if n%3==0 or n%5==0])

from timeit import timeit
pE1test1()
print timeit(pE1test2, number=1)

This outputs:

>>> 
233168
0.0090000629425
233168
0.00513921300363

What is the major difference between timeit and time?

  • 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-18T04:25:10+00:00Added an answer on June 18, 2026 at 4:25 am

    timeit will use the best available timing function on your system. See the docs on timeit.default_timer.

    Also, timeit turns off the garbage collector.

    Also, I believe you’re using timeit wrong. You should be passing a string as per the last example in the documentation:

    print timeit("pE1test2()","from __main__ import PE1test2",number=1)
    

    And of course, another major difference is that timeit makes it trivial to time the execution of the function for thousands of iterations (which is the only time a timing result is meaningful). This decreases the importance of a single run taking longer than the others (e.g. due to your system resources being hogged by some other program).

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

Sidebar

Related Questions

i was wondering if there is any significant difference between consuming .asmx services with
Is there any significant difference in performance between Canvas and XNA? What I mean:
Is there any significant performance difference between using of Describe method with Evaluate expression
In JSF 2.0, is there any significant technical difference between doing a non-AJAX submit
is there some significant difference between PHP 5.4 and 5.2.13 for the following code?
Recently I've been wondering if there is any significant difference between this code: public
Is there any significant difference between the two Python keywords continue and pass like
Is there any functional difference in Python between a try statement and an if
Is there any difference (compiler/interpreter/juju wise, etc) between the two versions of checking the
Possible Duplicate: C++: “std::endl” vs “n” I'm wondering if there is any significant difference

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.