Is your Framework fast or is it enough to test the performance of Hello World

    For example, the fastest frameworks "Phalcon" and "handmade".
    We overtake Phalcon without compiling the source code.




    Why exactly Phalcon? This is a fairly fresh and promising solution in terms of performance, although any framework can be in its place (this will become clear from the article).

    For testing, phalcon 1.2.0beta1 64Bit for OpenSuse was used.
    Of the additional libraries connected to PHP 5.3, there was only php5-APC, for the purity of the experiment.

    Guided by the manual, we create the Phaclon application
    index.php
    registerDirs(array(
            './app/controllers/',
            './app/models/'
        ))->register();
        //Create a DI
        $di = new Phalcon\DI\FactoryDefault();
        //Setting up the view component
        $di->set('view', function(){
            $view = new \Phalcon\Mvc\View();
            $view->setViewsDir('./app/views/');
            return $view;
        });
        //Handle the request
        $application = new \Phalcon\Mvc\Application($di);
        echo $application->handle()->getContent();
    } catch(\Phalcon\Exception $e) {
         echo "PhalconException: ", $e->getMessage();
    }
    

    ./app/controllers/IndexController.php
    Hello!";
        }
    }
    


    We start it, it works, memory_get_usage () says that 692kb of memory is used, an excellent result.
    Apache Benchmark delivers 8707 rps: Amazing, amazing performance. We look into the xdebug profile, optimism passes, and much becomes clear. What made this app so special? It is just echo. I have nothing against Phalcon, but what about more complex tasks? Is it possible to make a PHP framework that will be faster than Phalcon, without the need to compile the source code? No question, we’ll do it now. And then we will prove by tests that it is faster.








    Create a competitor, call it Handmade
    index.php:
    array(
    			'./app',
    			'./lib'
    	)		
    )); 
    $app = new Application();
    $app->run();
    

    Autoloader.php Autoloader
    decided to take from his project, saved time.
    The source code here , nothing particularly sophisticated, the usual PSR-0 compatible startup.

    ./lib/Application.php
    $action();
        }
    } 
    

    app / Index / Controller.php
    Hello!";
        }
    }
    


    We start, it works, memory_get_usage () says that 624kb of memory was used. Excellent result!

    Apache Benchmark produces 11793 rps: Voila 11793 versus 8707 rps, it turned out not so difficult, 15 minutes of programming, without optimizations. It remains to build beautiful graphics and put them closer to the title of the article. Probably, the question will arise, why did I suddenly decide that, you can compare his favorite framework "insert a name" with his hackwork that has no functionality at all. Take a look at the Internet, full of platform tests incomparable in goals and functionality.







    This is the whole point of the topic, let's take a look at the payload of the two compared solutions. Open the profile that xdebug provides us with. For visualization I will use kcachegrind.

    What do we see:
    PhalconHandmade



    Both solutions perform almost the same zero work.

    Why all this.

    As a developer, I often look at various solutions, the performance of the platform used is of no small importance to me. But, unfortunately, having opened the next framework, I can’t understand its real performance, the developers provide the Hello World test, which does not say anything at all. It’s difficult to navigate, it remains to find out the real performance of a particular platform based on personal experience and understanding of what is obviously slowing down the system.
    Indicators such as:
    • a large amount of "magic"
    • redundant abstraction and redundant functionality
    • ubiquitous use of DI Container
    • event-based architecture (not to be confused with Event-driven PHP )

    You have to choose a balanced solution for convenience, functionality and performance. The latter, in my opinion, is the easiest place to optimize.

    Morality

    Do not pay attention to populist slogans and beautiful advertising, trends. Learn as many solutions as possible, take the best out of them, combine successful implementations. Don't write or read tests Hello World is a waste of time. Choose a tool tailored to solve your specific problem.

    Also popular now: