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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:51:57+00:00 2026-05-27T08:51:57+00:00

I have created a benchmark class that allows the user to insert for example

  • 0

I have created a benchmark class that allows the user to insert for example

$timer->checkpoint('1');

to check out some code for time,memory consumption and such…. and at the end of the code if she/he wants to test it she/he has to insert

$result=$timer->result();

this gives out some data to public function result() like e.g. memory usage (using memory_get_peak_usage) and time consumption (microtime()).

This all works just fine for me.

But how can I use the combination of existing built-in php functions to get a value that can be considered a CPU consumption?

It has been quite easy to calculate how much time has been spent on a certain piece of code using the built-in functions, but I’ve been having trouble thinking of a way how to get the CPU consumption for a certain piece of code.

  • 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-27T08:51:58+00:00Added an answer on May 27, 2026 at 8:51 am

    Hate to answer my own question but I did a lot of research, and here I go…
    Basically what I did was this…

            $dat=getrusage();
            foreach ($dat as $key => $val) {
                $usertime= $dat['ru_utime.tv_usec'];
                $systemtime= $dat['ru_stime.tv_usec'];
                $finalresultcpu= ($systemtime + $usertime);
            }
            $this->_cpuTrackers[$name]=$finalresultcpu;
            return $this;
                                                  }
    

    As you can see I used a getrusage php built-in function. Which gives out an array with a whole bunch of info, of which most was pretty useless to me, except ru_utime.tv_usec(user time) and ru_stime.tv_usec(system time). To see how much CPU power the script has consumed, we need to look at the ‘user time’ and ‘system time’ values and as you can see in the code, add it to get the time which is in fact a cpu usage.

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

Sidebar

Related Questions

I have created a benchmark class that allows the user to insert for example
In some library code, I have a List that can contain 50,000 items or
I have some image processing Java code in Android that acts upon two large
I created a simple class to benchmark some methods of mine. But is it
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have created a webservice in .net 2.0, C#. I need to log some

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.