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

The Archive Base Latest Questions

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

I have this function, the input is the var cmd for example a dmesg

  • 0

I have this function, the input is the var “cmd” for example a dmesg command.

int i = 0;
char * bufferf;
bufferf = ( char * ) calloc( sizeof ( char ) , 200000 );
char buffer[1000][1280];
memset(buffer,0,1000 * 1280);
memset(bufferf,0,strlen(bufferf));
FILE* pipe = popen(cmd, "r");

if (!pipe){
    send(client_fd,"EXCEPTION",9,0);
}

while(!feof(pipe)) {
    if(fgets(buffer[i], 128, pipe) != NULL)
    {
        strcat(bufferf, buffer [i] );
    }
    i++;
}
pclose(pipe);
std::cout << bufferf ;
send(client_fd,bufferf,strlen(bufferf),0); }

Well. My goal is to calculate the amount of time between the start and the end of the while statement, by adding for each time a var that count the time passed.

For example dmesg is ~700 lines of output. The while runs for 700 times I have to add 700 times the amount of time to calculate the total sum.
How can I do that?
I’ve tried with difftime but it doesn’t work very well.
Any other solutions?

Thank you.

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

    You could make an extremely basic class that uses clock() to measure the time:

    #include <ctime>
    
    class Timer
    {
       private:
          clock_t _start, _duration;
       public:
          Timer() : _start(0), _duration(0) { }
    
          void start() { _start = clock(); }
          void stop() { _duration = clock() - _start; }     
          float getTime() { return (float)_duration / CLOCKS_PER_SEC; }
    };
    

    Obviously multiply by 1000 if you want to display the time in milliseconds.

    And then just:

    Timer t;
    t.start();
    // do something
    t.stop();
    
    cout << "Duration: " << t.getTime() << endl;
    

    Also, take note of what sarnold said, buffer is huge.

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

Sidebar

Related Questions

I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
I have this piece of code: $(input).keyup(function() { var searchTerms = getSearch(); doSearch(searchTerms); });
I currently have this function which appends an input to the #cursor-start div: var
I have the following action: $('.sub_outworker').live('click', function() { var input = $(this); var current_div
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have this function that takes the input of a, runs a calculation and
I have this: $(document).ready(function() { $(input[type=button]).click(function () { $(#test).html(W3Schools); alert(Would submit: + $(this).siblings(input[type=text]).val()); $.ajax({
I have this event listener: input_1.addEventListener('input',function(){ updateFromInput(1); },false); It controls the location of a
I'm calling a function from an input radio button and have this: onClick=\changeBilling('.$results['id'].', this.value)\
I have some jQuery code like this : $(function($) { $('input.autonumeric').autoNumeric({aSep: ',', aDec: '.',vMax:'1000000000000'});

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.