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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:50:48+00:00 2026-05-29T19:50:48+00:00

I want to compute how many times my computer can do counter += 1

  • 0

I want to compute how many times my computer can do counter += 1 in one second. A naive approach is the following:

from time import time

counter = 0
startTime = time()

while time() - startTime < 1:
    counter += 1

print counter

The problem is time() - startTime < 1 may be considerably more expensive than counter += 1.

Is there a way to make a less “clean” 1 sec sample of my algorithm?

  • 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-05-29T19:50:49+00:00Added an answer on May 29, 2026 at 7:50 pm

    The usual way to time algorithms is the other way around: Use a fixed number of iterations and measure how long it takes to finish them. The best way to do such timings is the timeit module.

    print timeit.timeit("counter += 1", "counter = 0", number=100000000)
    

    Note that timing counter += 1 seems rather pointless, though. What do you want to achieve?

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

Sidebar

Related Questions

I want to know how many games my computer can play in 1000 ms.
I want to compute the time 4 hours later during the DST transition, either
I am designing a problem in which I want to find how many times
I'm planning an application which will involve loading many pictures at one time and
For use in a rigid body simulation, I want to compute the mass and
I want to ask how to add a computed column in BIRT that compute
I want (barely computer literate) people to easily submit a large number of files
I am using CoreGraphics to draw a quadratic bezier but want to computer the
May be it sound dumb but if I want some computed value from other
I want to verify if a computer is running .net 3.5 or 3.5 sp1,

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.