Skip to content

Commit d7faeb0

Browse files
committed
Crypt: update benchmarks
1 parent 4c03402 commit d7faeb0

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

crypt/benchmark.phps

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
$keys = array('movable-type.php', 'phpaes.php', 'phpclasses1.php', 'phpclasses2.php', 'phpseclib.php');
3+
4+
$results = array();
5+
6+
foreach ($keys as $bin) {
7+
echo "php55 $bin";
8+
9+
$result = preg_replace('#.*Elapsed time: #', '', shell_exec("php55 $bin"));
10+
$result2= preg_replace('#.*Elapsed time: #', '', shell_exec("php55 $bin"));
11+
12+
$elapsed = ($result + $result2) / 2;
13+
14+
$results[$bin .'s'] = $elapsed;
15+
16+
echo " = $elapsed\r\n";
17+
}
18+
19+
echo "\r\n";
20+
21+
foreach ($results as $key => $result) {
22+
echo ' <tr>
23+
<td><a href="' . $key . '">' . $key . '</a></td>
24+
<td>' . $result . '</td>
25+
</tr>';
26+
echo "\r\n";
27+
}

crypt/examples.html

+8-12
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ <h2>RC2 is a Block Cipher</h2>
290290
<div id="speed" class="aes rijndael">
291291
<div class="cbc ecb">
292292
<h2>Speed Comparisons</h2>
293-
<p>The following table compares the speed of five different pure-PHP implementations of AES (one of which is Crypt_Rijndael and one of which is Crypt_AES) when ran on 1MB of text on a 1.73GHz Intel Core i7-820QM with PHP 5.4.3. The numbers listed are averaged from five different trials and are measured in seconds. phpseclib's two implementations are highlighted. All implementations can be viewed by clicking on their names.</p>
293+
<p>The following table compares the speed of five different pure-PHP implementations of AES when ran on 1MB of text on an Intel Core i5-3320M CPU @ 2.6GHz with PHP 5.5.3. The numbers listed are averaged from two different trials and are measured in seconds. phpseclib's implementation is highlighted. All implementations can be viewed by clicking on their names and the table was generated with <a href="benchmark.phps">benchmark.phps</a>.</p>
294294
<table>
295295
<thead>
296296
<tr>
@@ -301,31 +301,27 @@ <h2>Speed Comparisons</h2>
301301
<tbody>
302302
<tr>
303303
<td><a href="movable-type.phps">movable-type.phps</a></td>
304-
<td>28.2514320611955</td>
304+
<td>21.164710998535</td>
305305
</tr>
306306
<tr>
307307
<td><a href="phpaes.phps">phpaes.phps</a></td>
308-
<td>50.1811164617535</td>
308+
<td>37.811162352562</td>
309309
</tr>
310310
<tr>
311311
<td><a href="phpclasses1.phps">phpclasses1.phps</a></td>
312-
<td>22.9090529680255</td>
312+
<td>17.648010134697</td>
313313
</tr>
314314
<tr>
315315
<td><a href="phpclasses2.phps">phpclasses2.phps</a></td>
316-
<td>51.9629266262055</td>
316+
<td>43.407482504844</td>
317317
</tr>
318318
<tr style="background: yellow">
319-
<td><a href="phpseclib-aes.phps">phpseclib-aes.phps</a></td>
320-
<td>1.92589354515075</td>
321-
</tr>
322-
<tr style="background: yellow">
323-
<td><a href="phpseclib-rijndael.phps">phpseclib-rijndael.phps</a></td>
324-
<td>3.30701446533205</td>
319+
<td><a href="phpseclib.phps">phpseclib.phps</a></td>
320+
<td>1.0410599708557</td>
325321
</tr>
326322
</tbody>
327323
</table>
328-
<p>As can be seen, phpseclib's implementations are the fastest. phpseclib-aes.phps is faster than phpseclib-rijndael.phps because phpseclib-rijndael.phps has to contend with multiple block sizes whereas phpseclib-aes.phps does not. Note that if mcrypt weren't explicitily disabled phpseclib would have been even faster.</p>
324+
<p>As can be seen, phpseclib's implementations are the fastest. Note that if mcrypt weren't explicitily disabled phpseclib would have been even faster.</p>
329325
</div>
330326
</div>
331327
</div>

crypt/phpseclib.phps

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
// 1.8914740085602
3+
// 1.9603130817413
4+
5+
// http://phpseclib.sourceforge.net/
6+
7+
include('Crypt/AES.php');
8+
9+
$plaintext = '';
10+
for ($i = 0; $i < 1024*1024; $i++) {
11+
$plaintext.= chr(mt_rand(0, 255));
12+
}
13+
14+
$start = microtime(true);
15+
16+
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
17+
$aes = new Crypt_AES();
18+
$aes->setKey('abcdefghijklmnop');
19+
$aes->encrypt($plaintext);
20+
21+
$elapsed = microtime(true) - $start;
22+
echo "Elapsed time: $elapsed";

0 commit comments

Comments
 (0)