Speed test with BF

In general, performance is not the most important factor in the developers' checklist when choosing a PHP framework. In my personal opinion, there are two main reasons for that. The first one, there is an assumption frameworks should take care of everything and it supposed to be fast enough. The second reason, the major of applications are not critical and developers prefer to rely the application performance on robust servers.

So, considering performance as an important factor I have run some speed tests to compare the performance of the main frameworks available on the market.

  1. Laravel
  2. Symfony
  3. Code Ignitor
  4. Zend Framework
  5. Bossanova Framework

 

It was performed two main tests:

  1. A simple controller to return Hello World;
  2. A simple controller to connect and print a record content from the database;

 

So, to facilitate the tests and make easier the test replications.

  1. I have used the Bitnami Wamp 5.5.25-0 as my Apache Server with MySQL;
  2. I have used the frameworks included in the distribution of the Bitnami Wamp 5.5.25-0;
  3. I have used the Bossanova v2.0.1
  4. The configuration of my computer:
     

Tests

In order to have a very easy way to compare the performances I have included in the main file from each framework the following code:

<?php

$time_start = microtime(true);

(...)

$time_end = microtime(true);

echo $time = $time_end - $time_start;

 

Hello World Tests

To perform this tests I have taken each framework distribution and create a very basic controller and route. Then I have run each controller 10 times and collected the total execution time from each return.

 

Laravel

http://laravel/

Hello World

<?php namespace App\Http\Controllers;

class WelcomeController extends Controller
{
    public function index()
    {
        return 'Hello World! ';
    }
}

Return a single record from the database

<?php namespace App\Http\Controllers;

class WelcomeController extends Controller
{
    public function index()
    {
        $results = \DB::select('select * from users where user_id = 1');

        return print_r($results, true);
    }
}

Symfony

http://symfony/app/example

Hello World

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
    /**
     * @Route("/app/example", name="homepage")
     */
    public function indexAction()
    {
        return new Response('Hello World! ');
    }
}

Return a single record from the database

<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $stmt = $this->getDoctrine()->getConnection()->prepare('select * from users where 1');
        $stmt->execute();
        $result = $stmt->fetchAll();

        return new Response(print_r($result, true));
    }
}


Zend Framework

http://zendframework/

Hello World

<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        echo 'Hello World! ';

        return $this->getResponse();
    }
}

Return a single record from the database

<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Db\Adapter\Adapter;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        $adapter = new Adapter(array(
            'driver' => 'Mysqli',
            'hostname' => '127.0.0.1',
            'database' => 'bossanova',
            'username' => 'root',
            'password' => ''
        ));

        $result = $adapter->query('select * from users where user_id = 1')->execute()->current();

        print_r($result);

        return $this->getResponse();
    }
}

Code Igniter

http://codeigniter/

Hello World

<?php

class Welcome extends CI_Controller
{
    public function index()
    {
        echo 'Hello World! ';
    }
}

Return a single record from the database

<?php

class Welcome extends CI_Controller
{
    public function index()
    {
        $config['hostname'] = '127.0.0.1';
        $config['username'] = 'root';
        $config['password'] = '';
        $config['database'] = 'bossanova';
        $config['dbdriver'] = 'mysqli';
        $this->load->database($config);

        $query = $this->db->query("select * from users where user_id = 1");
        $count =  $query->row_array(); // returns an asociative array of the result
        print_r($count);
    }
}

Bossanova Framework

http://bossanova/

Hello World

<?php

namespace modules\Home;

use bossanova\Module\Module;

class Home extends Module
{
    public function __default ()
    {
        // Make sure no layout is loaded.
        $this->setLayout(0);

        return 'Hello World! ';
    }
}

Return a single record from the database

<?php

namespace modules\Home;

use bossanova\Module\Module;

class Home extends Module
{
    public function __default ()
    {
        // Make sure no layout is loaded.
        $this->setLayout(0);

        // Query user
        $this->query->setQuery('select * from users where user_id = 1');
        $result = $this->query->Execute();
        return print_r($this->query->fetch_assoc($result), true);
    }
}

Results

Framework Hello World (AVG)  Return a record (AVG)
Laravel 0.0616271972656251 0.0928825378417971
Symfony 0.0764420509338380 0.1064771175384530
ZF2 0.1119954347610480 0.1326846361160280
Code Igniter 0.0123974323272707 0.0280403375625611
Bossanova  0.0090357780456543 0.0191423416137696

 

Sample

 

 

Conclusion

Considering this simple example, BF has shown the best performance in both situations, followed by Codeignater and Laravel. Please, feel free to replicate the test in your development enviroment and feel free to send us your comments.

benchmark,laravel,symfony,code ignitor,zend framework,bossanova framework