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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:59:05+00:00 2026-05-24T18:59:05+00:00

I am trying to write a benchmark program that takes about 20 minutes to

  • 0

I am trying to write a benchmark program that takes about 20 minutes to complete because the actual functions need to be called at least 50 times.

I used the following code:

struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
usleep(2000);
gettimeofday(&end,NULL);
seconds =end.tv_sec - start.tv_sec;
useconds=end.tv_usec - start.tv_usec; 
(mtime>1000)?cout<<"elapsed time in seconds:"<<setprecision(8)<<mtime/1000<<"seconds\n":cout<<"elapsed time in milliseconds: "<<setprecision(3)<<mtime<<" milliseconds\n"; 

but I am required to write it in such a way that the output deduces the best units to use for the elapsed time and displays the results in those units. any suggestions how I can revise the above code for the requirement? thx!

  • 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-24T18:59:06+00:00Added an answer on May 24, 2026 at 6:59 pm

    My guess is that your “best unit” requirement is basically “human usable units.” If so, take the time and

    • millisecs mod 1000 gives number of milliseconds
    • millisecs div 1000 gives seconds (where div is integer division)
    • seconds mod 60 gives number of seconds
    • seconds div 60 gives minutes

    and so on.

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

Sidebar

Related Questions

Trying to write a couple of functions that will encrypt or decrypt a file
I'm trying write a C program that sends an UDP packet to a given
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
im trying to write an app that will display a list off lines from
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
Trying to write this small program to help me in my Stats class, everything
I'm trying write a simple perl script that reads some fields from a password
Im trying to write out an image file that has the following structure: P5
Im trying to write to an API and I need to call an eventhandler

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.