Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
117 lines (96 sloc) 3.11 KB
<?php
declare(strict_types=1);
include_once 'vendor/autoload.php';
$blackfire = new \Blackfire\Client();
$numberOfElements = 100;
$arrayToIterate = [];
$nonce = '';
$nonceArray = [];
class ExampleObject
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $firstName;
/**
* @var string
*/
public $lastName;
/**
* @var string
*/
public $fullName;
/**
* @var string
*/
public $comment;
/**
* @var int
*/
public $accessLevel;
public function __construct(int $id, string $firstName, string $lastName, string $fullName, string $comment, int $accessLevel)
{
$this->id = $id;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->fullName = $fullName;
$this->comment = $comment;
$this->accessLevel = $accessLevel;
}
}
$generateRandomName = function ($maxElements): string {
$subString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas cursus libero eget diam condimentum, blandit ullamcorper arcu pellentesque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque faucibus pretium dictum. Nulla mollis eros at nunc consectetur efficitur. ' . \mt_rand(0, $maxElements + 1);
return \str_shuffle($subString);
};
for ($i = 0; $i < $numberOfElements; $i++) {
// Object version
// $arrayToIterate[] = new ExampleObject(
// \mt_rand(0, $numberOfElements + 1),
// $generateRandomName($numberOfElements + 1),
// $generateRandomName($numberOfElements + 1),
// $generateRandomName($numberOfElements + 1),
// $generateRandomName($numberOfElements + 1),
// \mt_rand(0, $numberOfElements + 1)
// );
// Array version
// $arrayToIterate[] = [
// "id" => \mt_rand(0, $numberOfElements + 1),
// "firstName" => $generateRandomName($numberOfElements + 1),
// "lastName" => $generateRandomName($numberOfElements + 1),
// "fullName" => $generateRandomName($numberOfElements + 1),
// "comment" => $generateRandomName($numberOfElements + 1),
// "accessLevel" => \mt_rand(0, $numberOfElements + 1)
// ];
// StdClass version
$obj = new \stdClass();
$obj->id = \mt_rand(0, $numberOfElements + 1);
$obj->firstName = $generateRandomName($numberOfElements + 1);
$obj->lastName = $generateRandomName($numberOfElements + 1);
$obj->fullName = $generateRandomName($numberOfElements + 1);
$obj->comment = $generateRandomName($numberOfElements + 1);
$obj->accessLevel = \mt_rand(0, $numberOfElements + 1);
$arrayToIterate[] = $obj;
}
$probe = $blackfire->createProbe();
// Test #1
foreach ($arrayToIterate as $item) {
$nonce = $item->fullName;
// $nonce = $item['fullName'];
}
// Test #2
//foreach ($arrayToIterate as $item) {
// $item->id *= $numberOfElements;
//// $item['id'] *= $numberOfElements;
//}
// Test #3
//foreach ($arrayToIterate as $item) {
// $nonceArray[] = $item;
// $item->id *= $numberOfElements;
//// $item['id'] *= $numberOfElements;
//}
$profile = $blackfire->endProbe($probe);
You can’t perform that action at this time.