cypher18

2019-09-07 14:53:51
Autor: Grzesiek Tarka
<?php

declare(strict_types=1);

namespace App\Controller\Front\Blog;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class BlogController extends AbstractController
{
    #[Route('/blog', name: 'blog', priority: 1)]
    public function index(Request $request): Response
    {
        $timeStart = microtime(true);

        $data = [];

        for ($i = 1; $i <= 5000000; $i++) {
            $num = 5;
            $location = 'tree';
            $format = 'There are %s monkeys in the %s test %s';
            $data[] = sprintf($format, $num, $location, $i);
        }
        echo count($data);
        $endtime = microtime(true);
        $duration = $endtime - $timeStart;
        $milliseconds = round($duration * 1000);
        echo '<h3><b>czas</b> ' . $milliseconds . ' milliseconds</h3>';
        die;
    }
}

 

//bez niczego
129.917 seconds

//wersja z use function
115.557 seconds

wersja z back slashem
116.523 seconds

<?php

declare(strict_types=1);

namespace App\Controller\Front\Blog;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class BlogController extends AbstractController
{
    #[Route('/blog', name: 'blog', priority: 1)]
    public function index(Request $request): Response
    {
        $timeStart = microtime(true);

        $data = [];

        for ($i = 1; $i <= 100000; $i++) {
            $num = 5;
            $location = 'tree';
            $format = 'There are %s monkeys in the %s test %s';
            $format2 = 'There are %s monkeys in the %s test %s';
            $format3 = 'There are %s monkeys in the %s test %s';
            $data[] = sprintf($format, $num, $location, $i);
            $data[] = sprintf($format2, $num, $location, $i);
            $data[] = sprintf($format3, $num, $location, $i);
        }
        echo count($data);
        $endtime = microtime(true);
        $duration = $endtime - $timeStart;
        $milliseconds = round($duration * 1000);
        echo '<h3><b>czas</b> ' . $milliseconds . ' milliseconds</h3>';
        die;
    }
}

90.595 seconds
82.123 seconds
80.918 seconds

ab -n 1000 -c 1 http://localhost/blog-symfony/public/blog

 

 

kategorie
Dodawanie komentarzy wyłączone

Komentarze 89