The benchmark main function.

@param array $timeKeeping
The timekeeping array.

@return array
The benchmark array.

@see http://php.net/manual/de/function.microtime.php
@author gomodo at free dot fr
509298
protected function miniBenchTo(array $timeKeeping)
    {
        // Get the very first key.
        $start = key($timeKeeping);
        $totalTime = round((end($timeKeeping) - $timeKeeping[$start]) * 1000, 4);
        $result['url'] = $this->getCurrentUrl();
        $result['total_time'] = $totalTime;
        $prevMomentName = $start;
        $prevMomentStart = $timeKeeping[$start];

        foreach ($timeKeeping as $moment => $time) {
            if ($moment !== $start) {
                // Calculate the time.
                $percentageTime = round(((round(($time - $prevMomentStart) * 1000, 4) / $totalTime) * 100), 1);
                $result[$prevMomentName . '->' . $moment] = $percentageTime . '%';
                $prevMomentStart = $time;
                $prevMomentName = $moment;
            }
        }

        return $result;
    }
663866
public static function timeDifferent($time1, $time2)
    {
        $intTime1 = $this->unixTime($time1);
        $intTime2 = $this->unixTime($time2);
        $timeDiff = $intTime2 - $intTime1;

        return $timeDiff;
    }
1258774
public function main()
    {
        $table = $this->loadModel('Audits');
        $table->hasMany('AuditDeltas');
        $table->schema()->columnType('created', 'text');
        $map = [];
        $meta = [];

        $featureList = function ($element) {
            list($k, $v) = explode(':', $element);
            yield $k => $v;
        };

        if (!empty($this->params['type-map'])) {
            $map = explode(',', $this->params['type-map']);
            $map = collection($map)->unfold($featureList)->toArray();
        }

        if (!empty($this->params['extra-meta'])) {
            $meta = explode(',', $this->params['extra-meta']);
            $meta = collection($meta)->unfold($featureList)->toArray();
        }

        $from = (new Time($this->params['from']))->modify('midnight');
        $until = (new Time($this->params['until']))->modify('23:59:59');

        $currentId = null;
        $buffer = new \SplQueue();
        $buffer->setIteratorMode(\SplDoublyLinkedList::IT_MODE_DELETE);
        $queue = new \SplQueue();
        $queue->setIteratorMode(\SplDoublyLinkedList::IT_MODE_DELETE);
        $index = ConnectionManager::get('auditlog_elastic')->getConfig('index');

        $eventsFormatter = function ($audit) use ($index, $meta) {
            return $this->eventFormatter($audit, $index, $meta);
        };
        $changesExtractor = [$this, 'changesExtractor'];

        $query = $table->find()
            ->where(function ($exp) use ($from, $until) {
                return $exp->between('Audits.created', $from, $until, 'datetime');
            })
            ->where(function ($exp) {
                if (!empty($this->params['exclude-models'])) {
                    $exp->notIn('Audits.model', explode(',', $this->params['exclude-models']));
                }

                if (!empty($this->params['models'])) {
                    $exp->in('Audits.model', explode(',', $this->params['models']));
                }
                return $exp;
            })
            ->matching('AuditDeltas')
            ->order(['Audits.created', 'AuditDeltas.audit_id'])
            ->bufferResults(false)
            ->hydrate(false)
            ->unfold(function ($audit) use ($buffer, &$currentId) {
                if ($currentId && $currentId !== $audit['id']) {
                    yield collection($buffer)->toList();
                }
                $currentId = $audit['id'];
                $buffer->enqueue($audit);
            })
            ->map($changesExtractor)
            ->map($eventsFormatter)
            ->unfold(function ($audit) use ($queue) {
                $queue->enqueue($audit);

                if ($queue->count() >= 50) {
                    yield collection($queue)->toList();
                }
            });

        $query->each([$this, 'persistBulk']);

        // There are probably some un-yielded results, let's flush them
        $rest = collection(count($buffer) ? [collection($buffer)->toList()] : [])
            ->map($changesExtractor)
            ->map($eventsFormatter)
            ->append($queue);

        $this->persistBulk($rest->toList());

        return true;
    }
237882
public static function compareTiem($timeA, $timeB)
    {
        $a=strtotime($timeA);
        $b=strtotime($timeB);
        if ($a > $b) {
            return 1;
        } elseif ($a == $b) {
            return 0;
        } else {
            return -1;
        }
    }
435511
public function getElapsedTimeInSeconds()
    {
        if(!$this->_timeStartInMicroSeconds)
        {
            return 0;
        }

        $microSecsStart = $this->_timeStartInMicroSeconds;
        $microSecsStop = $this->_timeStopInMicroSeconds;

        if($microSecsStop == 0)
        {
            // The function stopTimer was not called.
            $microSecsStop = microtime(true);
        }

        $seconds = $microSecsStop - $microSecsStart;

        return round($seconds, 4);
    }
510087
public static function get_microtime() {
        list($tps_usec, $tps_sec) = explode(' ', microtime());
        return (float) $tps_usec + (float) $tps_sec;
    }
179731
public static function execute()
    {
        $name = 'Benchmark-' . uniqid();

        $benchmark = new Benchmark($name);

        $args = func_get_args();

        foreach ($args as $k => $arg) {
            $benchmark->addTask('Task-' . ($k + 1), $arg);
        }

        return $benchmark->execute(static::$times)->render(static::$round);
    }
574174
def benchmark(times = 1, &block)
      elapsed = (1..times).collect do
        GC.start
        ::Benchmark.realtime(&block) * times
      end

      Result.new(elapsed)
    end
375274
public static function getMicroTime()
    {
        $returnValue = (float) 0.0;

        
        
        list($ms, $s) = explode(" ", microtime());
        $returnValue = $s+$ms;
        
        

        return (float) $returnValue;
    }
639609
public function timings($metrics)
    {
        // add |ms to values
        $data = [];
        foreach ($metrics as $metric => $timing) {
            $data[$metric] = $timing.'|ms';
        }

        return $this->send($data);
    }
598533
public function startBenchmark()
    {
        $this->_benchmark_starttime = microtime(true);
        $this->log(SMARTIRC_DEBUG_NOTICE, 'benchmark started', __FILE__, __LINE__);
        return $this;
    }
542355
public function showBenchmark()
    {
        $this->log(SMARTIRC_DEBUG_NOTICE, 'benchmark time: '
            .((float)$this->_benchmark_stoptime-(float)$this->_benchmark_starttime),
            __FILE__, __LINE__
        );
        return $this;
    }
633203
public static function getAverageTimeForArrayOfDateTimes($array)
    {
        if (!is_array($array)) {
            return false;
        }

        $averageTime = null;

        $averageSecondsFromDateBeginSum = 0;
        $processedItemsCounter = 0;

        foreach ($array as $datetime) {
            if (!is_object($datetime) || !($datetime instanceof \DateTime)) {
                continue;
            }

            $hours = (int)$datetime->format('H');
            $minutes = (int)$datetime->format('i');
            $seconds = (int)$datetime->format('s');

            $averageSecondsFromDateBeginSum += $hours * 3600 + $minutes * 60 + $seconds;
            $processedItemsCounter += 1;
        }

        $averageTime = gmdate('H:i:s', intval($averageSecondsFromDateBeginSum / $processedItemsCounter) % 86400);

        return $averageTime;
    }
875193
public function execute()
    {
        $results = array();
        foreach ($this->benchmarks as $benchmark) {
            $results += $benchmark->execute();
        }

        return $results;
    }
612998
public void startBenchmark() {
    startTime = System.currentTimeMillis();
    LOG.info("Start to benchmark chronos server");

    Thread t = new Thread() { // new thread to output the metrics
      @Override
      public void run() {
        final long collectPeriod = 10000;
        LOG.info("Start another thread to export benchmark metrics every " + collectPeriod / 1000.0
            + " second");

        int totalCount;
        int totalLatency;
        long exportTime;
        int lastTotalCount = 0;
        int lastTotalLatency = 0;
        long lastExportTime = startTime;

        while (true) {
          try {
            Thread.sleep(collectPeriod);
          } catch (InterruptedException e) {
            LOG.error("Interrupt when sleep to get benchmark metrics, exit immediately");
            System.exit(0);
          }

          exportTime = System.currentTimeMillis();
          totalCount = totalCountInteger.get();
          totalLatency = totalLatencyInteger.get();

          double totalCostTime = (exportTime - startTime) / 1000.0;
          double costTime = (exportTime - lastExportTime) / 1000.0;
          double qps = (totalCount - lastTotalCount) / costTime;
          double latency = (totalLatency - lastTotalLatency) * 1.0 / (totalCount - lastTotalCount);
          System.out.println("Total " + totalCostTime + ", in " + costTime + " seconds, qps: "
              + qps + ", latency: " + latency + "ms");

          lastTotalCount = totalCount;
          lastTotalLatency = totalLatency;
          lastExportTime = exportTime;
        }
      }
    };

    t.setDaemon(true);
    t.start();

    while (true) {
      try {
        long start = System.currentTimeMillis();
        currentTimestamp = chronosClient.getTimestamp();
        totalCountInteger.incrementAndGet();
        totalLatencyInteger.addAndGet((int) (System.currentTimeMillis() - start));

        if (currentTimestamp <= previousTimestamp) { // check correctness
          LOG.error("Fatal error to get a lower timestamp " + currentTimestamp + "(previous is "
              + previousTimestamp + "), exit immediately");
          System.exit(0);
        }
        previousTimestamp = currentTimestamp;

        if (isFailover == true) { // calculate failover time
          double failoverTime = (System.currentTimeMillis() - failoverStartTime) / 1000.0;
          System.out.println("After " + failoverStartTimeString + ", the total failover time is "
              + failoverTime + " seconds");
        }
        isFailover = false;
      } catch (IOException e) {
        LOG.error("Exception to get timestamp");

        if (isFailover == false) {
          failoverStartTime = System.currentTimeMillis();
          failoverStartTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(
              failoverStartTime));
          LOG.info("Failover occurs at " + failoverStartTimeString);
        }
        isFailover = true;
      }
    }

  }
292286
public static function timeBenchmark()
        {
            self::markTime('finish');
        
            $lastTime = 0;
            $startTime = 0;
            $p = 0;

            echo '<table cellpadding="3" cellspacing="1">
                    <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
                    <tbody>';

            foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
                if ($p > 0) {
                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
                } else {
                    $startTime = $thisTime;
                }
                
                $p++;
                $lastTime = $thisTime;
            }
            
            echo '</tbody><tfoot>
                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
            </tfoot>
            </table>';
        }
996900
private function getCurrentTime()
    {
        list ($msec, $sec) = explode(" ", microtime());
        return (float)$msec + (float)$sec;
    }