xref: /php-src/ext/hash/bench.php (revision 2cee1be6)
1#!/usr/bin/env php
2<?php
3
4error_reporting(E_ALL);
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
22asort($time, SORT_NUMERIC);
23foreach ($time as $a => $t) {
24    printf("%-12s %02.6f\n", $a, $t/1000000000);
25}
26