php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
bench.php
Go to the documentation of this file.
1#!/usr/bin/env php
2<?php
3
5
6$data = str_repeat("\x00", (int) ($argv[1] ?? (2 * 1024)));
7$time = array();
8foreach (hash_algos() as $algo) {
9 $time[$algo] = 0;
10}
11
12for ($j = 0; $j < 10; $j++) {
13 foreach (hash_algos() as $algo) {
14 $start = hrtime(true);
15 for ($i = 0; $i < 1000; $i++) {
16 hash($algo, $data);
17 }
18 $time[$algo] += hrtime(true)-$start;
19 }
20}
21
23foreach ($time as $a => $t) {
24 printf("%-12s %02.6f\n", $a, $t/1000000000);
25}
$t
Definition bench.php:386
str_repeat(string $string, int $times)
hrtime(bool $as_number=false)
printf(string $format, mixed ... $values)
const SORT_NUMERIC
asort(array &$array, int $flags=SORT_REGULAR)
$data
Definition bench.php:6
$time
Definition bench.php:7
hash_algos()
Definition hash.stub.php:51
hash(string $algo, string $data, bool $binary=false, array $options=[])
Definition hash.stub.php:12
error_reporting(?int $error_level=null)
#define E_ALL
Definition zend_errors.h:43