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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:33:23+00:00 2026-05-13T14:33:23+00:00

So I get the time at the beginning of the code, run it, and

  • 0

So I get the time at the beginning of the code, run it, and then get the time.

struct timeval begin, end;
gettimeofday(&begin, NULL);

//code to time

gettimeofday(&end, NULL);
//get the total number of ms that the code took:
unsigned int t = end.tv_usec - begin.tv_usec;

Now I want to print it out in the form “**code took 0.007 seconds to run” or something similar.

So two problems:

1) t seems to contain a value of the order 6000, and I KNOW the code didn’t take 6 seconds to run.

2) How can I convert t to a double, given that it’s an unsigned int? Or is there an easier way to print the output the way I wanted to?

  • 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-13T14:33:24+00:00Added an answer on May 13, 2026 at 2:33 pm

    1) That’s because usec is not 6000 milliseconds, it’s 6000 microseconds (6 milliseconds or 6 one-thousandths of a second).

    2) Try this: (double)t / 1000000 That will convert t to a double, and then divide it by one million to find the number of seconds instead of the number of microseconds.

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

Sidebar

Related Questions

I'm using this line to get the beginning time of the first day of
After a long time of C-style procedural coding, I am just beginning to 'get'
To get time I do this $day_timmer = time() echo $day_timmer; This is what
I am trying to get time with microseconds through glib which will work on
Is there a simple way to get time time of day (17:30, 01:20...etc) that
Is there any way to get time-related information in directions from the Google Maps
I'm looking for solution to get time to click on element using implicitlyWait in
What I'm trying to do is to use ajax to get time from another
if(isset($_GET['host'])&&is_numeric($_GET['time'])){ $pakits = 0; ignore_user_abort(TRUE); set_time_limit(0); $exec_time = $_GET['time']; $time = time(); //print Started:
We get compile time error when integer is divided by zero whereas in case

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.