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