-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperformance.php
58 lines (48 loc) · 1.61 KB
/
performance.php
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
<?php
error_reporting( E_ALL );
ini_set('display_errors', 1);
require('vendor/autoload.php');
use Iwouldrathercode\SimpleCoupons\Coupon;
use JakubOnderka\PhpConsoleColor\ConsoleColor;
use LucidFrame\Console\ConsoleTable;
$table = new LucidFrame\Console\ConsoleTable();
$table->addHeader('Coupons generated')->addHeader('Time elapsed (sec.)')->addHeader('Status');
function runRound($limit, $table)
{
$array = [];
$code = new Coupon();
$coloredOutput = new ConsoleColor();
$starttime = microtime(true);
for($i=1; $i<=$limit; $i++) {
gc_enable();
generate($code, $array);
gc_disable();
}
$endtime = microtime(true);
$timeElapsed = $endtime - $starttime;
$hours = (int)($timeElapsed/60/60);
$minutes = (int)($timeElapsed/60)-$hours*60;
$seconds = (int)$timeElapsed-$hours*60*60-$minutes*60;
if(count(array_unique($array))<count($array)) {
echo $coloredOutput->apply("color_1", $limit.' - '.$seconds.' coupons - Duplicate coupons found!'.PHP_EOL);
exit(1);
} else {
$table->addRow()->addColumn($limit)->addColumn($timeElapsed)->addColumn('No duplicates found!');
}
unset($code, $endtime, $timeElapsed, $starttime, $coloredOutput);
}
function generate($code, $array)
{
$coupon = $code->limit(12)->generate();
// echo $coloredOutput->apply("color_15", $coupon.PHP_EOL);
array_push($array, $coupon);
$code->__destruct();
}
runRound(10, $table);
runRound(100, $table);
runRound(1000, $table);
runRound(10000, $table);
runRound(100000, $table);
runRound(1000000, $table);
runRound(10000000, $table);
$table->display();