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 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 the following $().ready(function() { $(input[name^=totalRent_]).each(function() { var input = $(this); var name
I currently have this function which appends an input to the #cursor-start div: var
I have this (simplification): $(li).click(function{alert(test);}); <li> <input> </li> What's the best way to bind
$('input[type=checkbox]').unbind().click(function(e){ $(this).attr('checked', true) return false; }); I NEED to return false because I have
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have this function in my head: <head> window.onload = function(){ var x =
I have this function: function addButtonLookup() { var element = document.getElementById(btnToolBar); var index; for
I have this function: function countLitreKgSums(cProductIds){ var cLitreKgSums = new Array(); var cWeek =
I have this function: function disableDiv(divId, action){ var divId = byId(divId); if(action==true){ divId.style.display='none'; }

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.