Test polyfill performance

master
Anton Smirnov 2022-08-20 00:28:27 +03:00
commit 70a25ddea8
4 changed files with 151 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.idea
/vendor
/composer.lock

99
README.adoc Normal file
View File

@ -0,0 +1,99 @@
= Random polyfill performance
All tests were run on PHP 7.4 except for native.
== getInt(0, 65535)
[%header,cols="3,2,2,2,2,2"]
|===
|Env
|MT
|MT (legacy)
|Secure
|PCG
|xoshiro256**
|Native (PHP 8.2)
|0.1860
|0.1731
|2.5280
|0.1879
|0.1791
|GMP
|61.4810
|52.3708
|15.5489
|51.1160
|55.7959
|brick/math + GMP
|680.0640
|544.2760
|15.9061
|552.4859
|747.3629
|brick/math + bcmath
|3597.6019
|3243.9330
|14.3719
|5762.5852
|8369.9131
|brick/math
|2706.6810
|2706.6810
|14.2810
|665554.69*
|148175.72*
|===
* approximately, I used 100 iterations, then multipiled by 100
== nextInt()
[%header,cols="3,2,2,2,2,2"]
|===
|Env
|MT
|MT (legacy)
|Secure
|PCG
|xoshiro256**
|Native (PHP 8.2)
|0.1109
|0.1099
|2.4838
|0.1061
|0.1271
|GMP
|40.9720
|41.6300
|19.0270
|37.4460
|42.7251
|brick/math + GMP
|526.6640
|530.4639
|80.7271
|415.9460
|610.4870
|brick/math + bcmath
|3252.0561
|3229.5029
|323.1668
|5249.2309
|8450.3100
|brick/math
|2383.1699
|2419.9281
|1266.5899
|718118.50
|149826.31
|===

10
composer.json Normal file
View File

@ -0,0 +1,10 @@
{
"repositories": [{
"type": "vcs",
"url": "../random-polyfill"
}],
"require": {
"php": ">= 7.1",
"arokettu/random-polyfill": "dev-no-gmp"
}
}

39
test.php Normal file
View File

@ -0,0 +1,39 @@
<?php
use Random\Engine\Mt19937;
use Random\Engine\PcgOneseq128XslRr64;
use Random\Engine\Secure;
use Random\Engine\Xoshiro256StarStar;
use Random\Randomizer;
require __DIR__ . '/vendor/autoload.php';
// generate 10000 getInt and 10000 nextInt
$engines = [
'mt' => new Mt19937(),
'mt_legacy' => new Mt19937(null, MT_RAND_PHP),
'secure' => new Secure(),
'pcg' => new PcgOneseq128XslRr64(),
'xoshiro' => new Xoshiro256StarStar(),
];
foreach ($engines as $name => $engine) {
$r = new Randomizer($engine);
$time = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$r->getInt(0, 65535);
}
echo $name, ': getInt(): ', sprintf("%.4f", (microtime(true) - $time) * 1000), PHP_EOL;
$time = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$r->nextInt();
}
echo $name, ': nextInt(): ', sprintf("%.4f", (microtime(true) - $time) * 1000), PHP_EOL;
}