本文整理汇总了PHP中Executor::setPrepCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP Executor::setPrepCallback方法的具体用法?PHP Executor::setPrepCallback怎么用?PHP Executor::setPrepCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Executor
的用法示例。
在下文中一共展示了Executor::setPrepCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Executor
<?php
namespace BRS\PerformanceDiff;
$executor = new Executor('Testing getting a char in a string using indexing vs substrings.', 1000000, Executor::TARE | Executor::PROGRESS);
$executor->setPrepCallback(function ($executor) {
$string = '';
$pool = '1234567890qwertyuiopasdfghjklzxcvbnm';
while (strlen($string) > 10000) {
// hint hint...
$string .= $string[rand(0, strlen($pool) - 1)];
}
$executor->setPayload(array(strlen($string), $string));
});
$executor->setTareFunction(function ($payload) {
return rand(0, $payload[0] - 1);
});
$executor->setRerun(10);
$executor->addTest(new Test('Index', function ($payload) {
return $payload[1][rand(0, $payload[0] - 1)];
}));
$executor->addTest(new Test('Substr', function ($payload) {
return substr($string, rand(0, $payload[0]), 1);
}));
$executor->execute();
$executor->log(basename(__FILE__) . '.' . time());
示例2: Executor
<?php
namespace BRS\PerformanceDiff;
$executor = new Executor('Testing finding a Key by value using foreach and array_search.', 100, Executor::TARE | Executor::PROGRESS);
$executor->setPrepCallback(function ($executor) {
$executor->setPayload(range(10000, 1000000));
});
$executor->setTareFunction(function ($payload) {
$find = rand(0, 1000000);
return null;
});
$executor->setRerun(1);
$executor->addTest(new Test('Search', function ($payload) {
$find = rand(0, 1000000);
return array_search($find, $payload);
}));
$executor->addTest(new Test('FlipIsSet', function ($payload) {
$find = rand(0, 1000000);
$payload = array_flip($payload);
return isset($payload[$find]) ? $payload[$find] : null;
}));
$executor->addTest(new Test('ForEach', function ($payload) {
$find = rand(0, 1000000);
foreach ($payload as $key => $value) {
if ($value == $find) {
return $key;
}
}
return '';
}));