xref: /PHP-8.0/ext/hash/bench.php (revision 3d1e7d37)
1#!/usr/bin/env php
2<?php
3
4/*
5 This gives rather interesting results :)
6
7 Measures on a Notebook P4M-1.7 256MB Windows 2000:
8    sha1         0.556691
9    tiger160,3   0.774469
10    tiger192,3   0.776314
11    tiger128,3   0.777004
12    ripemd128    0.896674
13    sha256       1.011164
14    md5          1.016032
15    tiger160,4   1.056617
16    tiger128,4   1.063101
17    tiger192,4   1.069258
18    haval160,3   1.125099
19    haval128,3   1.125679
20    haval224,3   1.128017
21    haval192,3   1.130026
22    haval256,3   1.134846
23    ripemd160    1.150693
24    haval128,4   1.686261
25    haval192,4   1.687274
26    haval160,4   1.693091
27    haval256,4   1.699323
28    haval224,4   1.743094
29    haval160,5   2.003452
30    haval192,5   2.008341
31    haval256,5   2.009048
32    haval128,5   2.009555
33    haval224,5   2.015539
34    sha384       3.370734
35    sha512       3.381121
36    whirlpool    6.912327
37    snefru       9.268168
38
39 Measures on a Desktop P4-2.4 512MB Debian (Linux-2.4):
40    md5          0.147739
41    haval128,3   0.317006
42    haval192,3   0.317524
43    haval256,3   0.317526
44    haval160,3   0.323035
45    haval224,3   0.333318
46    ripemd128    0.353447
47    sha1         0.376200
48    ripemd160    0.413758
49    sha256       0.435957
50    haval160,4   0.452357
51    haval224,4   0.454531
52    haval128,4   0.458026
53    haval256,4   0.459051
54    haval192,4   0.468094
55    haval128,5   0.524262
56    haval160,5   0.529573
57    haval224,5   0.533655
58    haval256,5   0.534446
59    haval192,5   0.543726
60    tiger128,3   0.577975
61    tiger160,3   0.579951
62    tiger192,3   0.597111
63    tiger192,4   0.781408
64    tiger160,4   0.801243
65    tiger128,4   0.812239
66    sha512       1.298627
67    sha384       1.313607
68    whirlpool    1.556159
69    snefru       5.703742
70
71*/
72
73error_reporting(E_ALL&~E_NOTICE);
74
75$data = file_get_contents(__FILE__);
76$time = array();
77foreach (hash_algos() as $algo) {
78        $time[$algo] = 0;
79}
80
81for ($j = 0; $j < 10; $j++) {
82    foreach (hash_algos() as $algo) {
83        $start = microtime(true);
84        for ($i = 0; $i < 1000; $i++) {
85            hash($algo, $data);
86        }
87        $time[$algo] += microtime(true)-$start;
88    }
89}
90
91asort($time, SORT_NUMERIC);
92foreach ($time as $a => $t) {
93    printf("%-12s %02.6f\n", $a, $t);
94}
95?>
96