-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbenchmark_hash.php
More file actions
68 lines (49 loc) · 1.18 KB
/
benchmark_hash.php
File metadata and controls
68 lines (49 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @copyright Jorge Castro Castillo MIT License https://www.eftec.cl
* @version 1.1
*/
include "Collection.php";
set_time_limit(5000);
$instances=100;
echo "<h1>Hash speed ($instances instances)</h1>";
echo "<p>It tests the performance of hash</p>";
$data = "";
for($i = 0; $i < 1500; $i++) {
$data .= sha1("H:k - $i - k:H");
}
$res = [];
foreach (hash_algos() as $algo) {
$time = microtime(1);
for($i=0;$i<$instances;$i++) {
$hash = hash($algo, $data);
}
$time = (microtime(1) - $time) * 1000;
$length = strlen($hash);
$res[(string)$time][] = [
'format' => 'HEX',
"algo" => $algo,
"length" => $length,
"time" => $time
];
$time = microtime(1);
for($i=0;$i<$instances;$i++) {
$hash=hash($algo, $data, 1);
}
$length = strlen($hash);
$time = (microtime(1) - $time) * 1000;
$res[(string)$time][] = [
'format' => 'RAW',
'algo' => $algo,
"length" => $length,
"time" => $time
];
}
ksort($res);
$i = 0;
$final=[];
foreach($res as $time=>$data) {
$final[]=$data[0];
}
echo \mapache_commons\Collection::generateTable($final);
?>