1
0
mirror of https://github.com/php/php-src.git synced 2026-04-01 13:12:16 +02:00
Files
archived-php-src/ext/hash/bench.php
divinity76 6c71d3476b Use constant size string in hash bench.php
I don't like the previous behaviour where the bytes to hash change
every time the code changes, that may make it difficult to compare
hash() performance changes over time.

Use a fixed number instead, and allow passing an override for a
different length.

Closes GH-6386.

[ci skip]
2020-10-30 09:54:48 +01:00

26 lines
526 B
PHP
Executable File

#!/usr/bin/env php
<?php
error_reporting(E_ALL);
$data = str_repeat("\x00", (int) ($argv[1] ?? (2 * 1024)));
$time = array();
foreach (hash_algos() as $algo) {
$time[$algo] = 0;
}
for ($j = 0; $j < 10; $j++) {
foreach (hash_algos() as $algo) {
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
hash($algo, $data);
}
$time[$algo] += microtime(true)-$start;
}
}
asort($time, SORT_NUMERIC);
foreach ($time as $a => $t) {
printf("%-12s %02.6f\n", $a, $t);
}