Exemple #1
0
 public function start($generateRoutes, $passess)
 {
     $tests = [];
     for ($i = 0; $i < $passess; $i++) {
         $tests[$i] = ['time-create-collection' => 0, 'time-compilation' => 0, 'time-match-unexistent-route' => 0, 'time-total-with-compilation' => 0, 'time-import-from-array' => 0, 'time-match-unexistent-route-imported' => 0, 'time-total-without-compilation' => 0];
         $collection = new RouteCollection();
         $start = microtime(true);
         for ($j = 0; $j < $generateRoutes; $j++) {
             $method = rand(1, 20) == 1 ? $this->possibleMethods[rand(0, 6)] : 'get';
             $path = $this->possiblePaths[rand(0, count($this->possiblePaths) - 1)];
             $collection->{$method}(microtime(), $path['path'], microtime());
         }
         $tests[$i]['time-create-collection'] = number_format(microtime(true) - $start, 4);
         // ===================================================================================
         $start = microtime(true);
         $collection->compile();
         $tests[$i]['time-compilation'] = number_format(microtime(true) - $start, 4);
         // ===================================================================================
         $matcher = new RouteMatcher($collection);
         $start = microtime(true);
         try {
             $matcher->matchWith('/_____________________________unexistent-route_____________________________', 'GET');
         } catch (Exception $e) {
         }
         $tests[$i]['time-match-unexistent-route'] = number_format(microtime(true) - $start, 4);
         $tests[$i]['time-total-with-compilation'] = $tests[$i]['time-create-collection'] + $tests[$i]['time-compilation'] + $tests[$i]['time-match-unexistent-route'];
         // ===================================================================================
         $exported = $collection->exportToArray();
         $start = microtime(true);
         $newCollection = new RouteCollection($exported, $collection->isCompiled());
         $tests[$i]['time-import-from-array'] = number_format(microtime(true) - $start, 4);
         // ===================================================================================
         $matcher = new RouteMatcher($collection);
         $start = microtime(true);
         try {
             $matcher->matchWith('/_____________________________unexistent-route_____________________________', 'GET');
         } catch (Exception $e) {
         }
         $tests[$i]['time-match-unexistent-route-imported'] = number_format(microtime(true) - $start, 4);
         $tests[$i]['time-total-without-compilation'] = $tests[$i]['time-import-from-array'] + $tests[$i]['time-match-unexistent-route-imported'];
     }
     return $tests;
 }