Advertisement
Guest User

Untitled

a guest
Jul 14th, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('memory_limit', '1024M'); //  Oo
  4.  
  5. require 'vendor/autoload.php';
  6.  
  7. function generateCats($n) {
  8.     $categories = [];
  9.  
  10.     for ($i = 0; $i < $n; $i++) {
  11.         $categories[] = array(
  12.             'name' => 'categoriy-'.uniqid(),
  13.             'id'   => $i
  14.         );
  15.     }
  16.     return $categories;
  17. }
  18.  
  19. function generateProducts($n, $cats) {
  20.  
  21.     $products = [];
  22.  
  23.     for ($i = 0; $i < $n; $i++) {
  24.         $products[] = [
  25.             'name'     => uniqid(),
  26.             'catId'    => $cats[rand(0, count($cats)-1)]['id'],
  27.             'id'       => $i,
  28.             'quantity' => rand(0, 1000)
  29.         ];
  30.     }
  31.  
  32.     return $products;
  33. }
  34.  
  35. $categories = generateCats(100);
  36. $products   = generateProducts(100000, $categories);
  37.  
  38. xhprof_enable(XHPROF_FLAGS_CPU+XHPROF_FLAGS_MEMORY);
  39.  
  40. $result = from($categories)
  41.     ->orderBy('$cat ==> $cat["name"]')
  42.     ->groupJoin(
  43.     from($products)
  44.     ->where('$prod ==> $prod["quantity"] > 0')
  45.         ->orderByDescending('$prod ==> $prod["quantity"]')
  46.     ->thenBy('$prod ==> $prod["name"]'),
  47.     '$cat ==> $cat["id"]', '$prod ==> $prod["catId"]',
  48.     '($cat, $prods) ==> [
  49.            "name" => $cat["name"],
  50.            "products" => $prods
  51.        ]'
  52. );
  53.  
  54. $arr = $result->toArray();
  55.  
  56. $xhprof_data = xhprof_disable();
  57.  
  58. $XHPROF_ROOT = "/usr/local/Cellar/php55-xhprof/254eb24";
  59. include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_lib.php";
  60. include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_runs.php";
  61.  
  62. $xhprof_runs = new XHProfRuns_Default();
  63. $run_id      = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement