Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit', '1024M'); // Oo
- require 'vendor/autoload.php';
- function generateCats($n) {
- $categories = [];
- for ($i = 0; $i < $n; $i++) {
- $categories[] = array(
- 'name' => 'categoriy-'.uniqid(),
- 'id' => $i
- );
- }
- return $categories;
- }
- function generateProducts($n, $cats) {
- $products = [];
- for ($i = 0; $i < $n; $i++) {
- $products[] = [
- 'name' => uniqid(),
- 'catId' => $cats[rand(0, count($cats)-1)]['id'],
- 'id' => $i,
- 'quantity' => rand(0, 1000)
- ];
- }
- return $products;
- }
- $categories = generateCats(100);
- $products = generateProducts(100000, $categories);
- xhprof_enable(XHPROF_FLAGS_CPU+XHPROF_FLAGS_MEMORY);
- $result = from($categories)
- ->orderBy('$cat ==> $cat["name"]')
- ->groupJoin(
- from($products)
- ->where('$prod ==> $prod["quantity"] > 0')
- ->orderByDescending('$prod ==> $prod["quantity"]')
- ->thenBy('$prod ==> $prod["name"]'),
- '$cat ==> $cat["id"]', '$prod ==> $prod["catId"]',
- '($cat, $prods) ==> [
- "name" => $cat["name"],
- "products" => $prods
- ]'
- );
- $arr = $result->toArray();
- $xhprof_data = xhprof_disable();
- $XHPROF_ROOT = "/usr/local/Cellar/php55-xhprof/254eb24";
- include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_lib.php";
- include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_runs.php";
- $xhprof_runs = new XHProfRuns_Default();
- $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement