Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @class benchmarking tools
- * @author Jordan Doyle
- * @description use this for simple benchmarking!
- */
- namespace benchmark;
- class tools
- {
- /*
- * @function **none**
- * @description defines vars
- */
- public $_start,
- $_end;
- $_benchmark;
- /*
- * @function start
- * @description starts the timer. (microtime(true))
- */
- public function start()
- {
- $this->_start = microtime(true);
- return true;
- }
- /*
- * @function stop
- * @description stops the timer. (microtime(true)).
- */
- public function stop()
- {
- $this->_end = microtime(true);
- return $this;
- }
- /*
- * @function end
- * @description finishes everything by subtracting the 2 floats and working out the decimals.
- */
- public function end($decimals)
- {
- $this->_benchmark = numberformat( ($this->_start - $this->_end), $decimals );
- return $this->_benchmark;
- }
- /*
- * @function flush
- * @description nulls all the vars.
- */
- public function flush()
- {
- $this->_benchmark = NULL;
- $this->_start = NULL;
- $this->_end = NULL;
- return $this;
- }
- }
- // make an instance of the class, using your singleton (\benchmark\tools) name the var 'b'
- // now you need to start the benchmark, $b->start();
- // now when you need to stop it use $b->stop();
- // to output it... echo $b->end(5);
- // -----OR WITH THE NEW UPDATE YOU CAN NOW DO $b->stop()->end(5); The integer in end is how many decimals...
Advertisement
Add Comment
Please, Sign In to add comment