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

  • Home
  • SEARCH
  • 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 1044615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:51:22+00:00 2026-05-16T15:51:22+00:00

I was trying to program a Timer class (unaware that boost had one), then

  • 0

I was trying to program a Timer class (unaware that boost had one), then when that wasn’t working, I tried to just output the value of clock(), using this code:

#include <ctime>
#include <iostream>

int main()
{
 for(int i = 0; i < 50; ++i)
 {
  std::cout << std::clock() << " ";
 }
 return 0;
}

When I run the program, I get a series of 0s. I have a similar experience when using boost thread sleep functions to spread out timing a little longer (although after a few seconds, it jumps from 0 to 10,000 and keeps outputting 10,000).

I’m running Gentoo Linux. Is this a platform thing? A C++ thing? What’s going on?

Edit: Strangely the jump to 10000 comes after a number of seconds, not milliseconds. When I was sleeping my thread for a second at a time, it took five or six seconds to get to 10000. However, if I’m understanding correctly. The time the thread spends sleeping doesn’t contribute towards the clock() count? (Which would make sense; why would it be executing clock cycles if it’s sleeping?)

  • 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-16T15:51:22+00:00Added an answer on May 16, 2026 at 3:51 pm

    The clock() return value is specified in microseconds. But typical granularity of whatever low-level system call the clock() implementation uses is much lower. So it seems that on your system the granularity is 10ms. Also note that clock() does NOT measure real time – it measures CPU time used by the program. So the time flows when your program controls the CPU, and it freezes when your program is suspended – sleeping, for example.

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One way to do this is to call InvalidateRect() with… May 16, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer Take a look at MOGenerator. It'll help with the regenerating… May 16, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer We actually need this where I work. I whipped together… May 16, 2026 at 4:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Okay so I'm trying to make a little gag program that will run away
I am trying to flash the background colour in a textfield. My timer setup
I am trying to figure out the memory consumption by my (C++) program using
My question is one I have pondered around when working on a demanding network
I'm trying to make my C# application multi threaded because sometimes, I get an
Consider the following code : class TestTimerGC : Form { public TestTimerGC() { Button
I have the following code, does this run an endless loop? I am trying
I am currently using select() to act as a timer. I have network receive
I have a few different OBJ files that I am able to parse and
I'm building a program in WPF which must feature multi-language support, with the ability

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.