-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to emulate datasets to test execution times
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use Sweikenb\Library\Dirty\Model\ConfigModel; | ||
use Sweikenb\Library\Dirty\Service\DirtyCheckService; | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
$rdata = require __DIR__.'/data/random_data.inc.php'; | ||
|
||
// config | ||
$numItems = 1000; | ||
|
||
// create items | ||
$items = []; | ||
for ($i = 0; $i < $numItems; ++$i) { | ||
$item = $rdata(mt_rand(5, 50)); | ||
$items[] = $item; | ||
$items[] = $item; | ||
} | ||
$actualItems = count($items); | ||
shuffle($items); | ||
|
||
// get instance | ||
$dirtyCheck = new DirtyCheckService(); | ||
|
||
// set exclude config | ||
$exclude = new ConfigModel(ignoreFieldPath: [ | ||
'owner.password', | ||
'owner.passwordSalt', | ||
'owner.passwordSalt', | ||
'owner.locationDetails.date', | ||
'owner.preferences.date', | ||
'reference.date', | ||
'tags.0.date', | ||
'tags.1.date', | ||
'categories.0.date', | ||
'categories.1.date', | ||
'createdAt', | ||
'updatedAt', | ||
]); | ||
|
||
// measure execution time | ||
$start = microtime(true); | ||
foreach ($items as $item) { | ||
$result = $dirtyCheck->execute($item['id'], $item, $exclude); | ||
} | ||
$finish = microtime(true); | ||
|
||
// process results | ||
$diff = $finish - $start; | ||
fwrite(STDOUT, sprintf("\nItems processed: %s", $actualItems)); | ||
fwrite(STDOUT, sprintf("\nExecution Time: %s", $diff)); | ||
fwrite(STDOUT, sprintf("\nAvg. Time/Item: %s", $diff / $actualItems)); | ||
fwrite(STDOUT, "\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
function randomStr(int $length = 25): string | ||
{ | ||
$signs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
$max = mb_strlen($signs) - 1; | ||
|
||
$buffer = ''; | ||
for ($i = 0; $i < $length; ++$i) { | ||
$buffer .= $signs[mt_rand(0, $max)]; | ||
} | ||
|
||
return $buffer; | ||
} | ||
|
||
class User | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self( | ||
mt_rand(1000, 100000), | ||
randomStr(), | ||
sprintf('%s@%s.com', randomStr(15), randomStr(15)), | ||
randomStr(), | ||
randomStr(), | ||
SimpleVal::create(), | ||
SimpleVal::create(), | ||
); | ||
} | ||
|
||
public function __construct( | ||
public readonly int $id, | ||
public readonly string $name, | ||
public readonly string $email, | ||
public readonly string $password, | ||
public readonly string $passwordSalt, | ||
public readonly SimpleVal $locationDetails, | ||
public readonly SimpleVal $preferences, | ||
) { | ||
} | ||
} | ||
|
||
class SimpleVal | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self( | ||
mt_rand(1000, 100000), | ||
randomStr(), | ||
randomStr(), | ||
new DateTime('now') | ||
); | ||
} | ||
|
||
public function __construct( | ||
public readonly int $id, | ||
public readonly string $key, | ||
public readonly string $value, | ||
public readonly DateTime $date, | ||
) { | ||
} | ||
} | ||
|
||
return function (int $numFields = 30) { | ||
$fields = []; | ||
for ($i = 0; $i < $numFields; ++$i) { | ||
$code = randomStr(); | ||
$fields[$code] = [ | ||
'code' => $code, | ||
'data' => SimpleVal::create(), | ||
]; | ||
} | ||
|
||
return [ | ||
'id' => mt_rand(100, 10000), | ||
'owner' => User::create(), | ||
'slug' => randomStr(), | ||
'name' => randomStr(), | ||
'reference' => SimpleVal::create(), | ||
'tags' => [ | ||
SimpleVal::create(), | ||
SimpleVal::create(), | ||
], | ||
'categories' => [ | ||
SimpleVal::create(), | ||
SimpleVal::create(), | ||
], | ||
'fields' => $fields, | ||
'details' => randomStr(500), | ||
'createdAt' => new DateTime('-10 days'), | ||
'createdBy' => User::create(), | ||
'updatedAt' => new DateTime('now'), | ||
'updatedBy' => User::create(), | ||
]; | ||
}; |