timer example


    protected $title = 'Timers';

    /** * Child classes should implement this to return the timeline data * formatted for correct usage. */
    protected function formatTimelineData(): array
    {
        $data = [];

        $benchmark = Services::timer(true);
        $rows      = $benchmark->getTimers(6);

        foreach ($rows as $name => $info) {
            if ($name === 'total_execution') {
                continue;
            }

            $data[] = [
                'name'      => ucwords(str_replace('_', ' ', $name)),
                'component' => 'Timer',
                'start'     => $info['start'],
                
/** * A convenience method for working with the timer. * If no parameter is passed, it will return the timer instance. * If callable is passed, it measures time of callable and * returns its return value if any. * Otherwise will start or stop the timer intelligently. * * @return Timer */
    function timer(?string $name = null, ?callable $callable = null)
    {
        $timer = Services::timer();

        if (empty($name)) {
            return $timer;
        }

        if ($callable !== null) {
            return $timer->record($name$callable);
        }

        if ($timer->has($name)) {
            return $timer->stop($name);
        }

    protected function startBenchmark()
    {
        if ($this->startTime === null) {
            $this->startTime = microtime(true);
        }

        $this->benchmark = Services::timer();
        $this->benchmark->start('total_execution', $this->startTime);
        $this->benchmark->start('bootstrap');
    }

    /** * Sets a Request object to be used for this request. * Used when running certain tests. * * @param CLIRequest|IncomingRequest $request * * @return $this */
Home | Imprint | This part of the site doesn't use cookies.