Skip to content

Commit d43773d

Browse files
committed
Adding performance tests
1 parent 05925e1 commit d43773d

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed

performance/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
vendor
3+
startDocker.sh

performance/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Performance
2+
===========
3+
4+
Composer's autoloader need to [require all Safe files](https://github.com/thecodingmachine/safe/blob/05925e1d2abe0c0fee2095c1d569a1302a1a209e/composer.json#L13-L97)
5+
on each request (since there is no autoloader for functions in PHP).
6+
7+
"Requiring" those ~84 files in PHP has a performance impact. We used [Blackfire](http://blackfire.io/) to time precisely the impact of loading the PHP files.
8+
9+
Results
10+
-------
11+
12+
| ||
13+
|-----------------------------------------------------------------------------------------------------------|-------|
14+
|[Composer autoload without Safe](https://blackfire.io/profiles/cb9122ac-69a7-4e90-9ea7-bf7561058815/graph) | 264µs |
15+
|[Composer autoload with Safe](https://blackfire.io/profiles/35eb02eb-60f8-480a-bad0-0cfc43179c18/graph) | 1.03ms |
16+
17+
Safe load time: **~700µs**
18+
19+
Only 700µs for loading 84 files containing 1000+ functions. Damn, PHP is fast! Opcache does a very good job.
20+
21+
The tests have been performed on a DELL XPS 9550 laptop running Ubuntu 18.04 and Docker. CPU: [Intel(R) Core(TM) i7-6700HQ](https://ark.intel.com/products/88967/Intel-Core-i7-6700HQ-Processor-6M-Cache-up-to-3-50-GHz-)
22+
23+
Reproducing the test
24+
--------------------
25+
26+
There are 2 test files:
27+
28+
- `test_with_safe/index.php`: loads Composer autoloader with Safe
29+
- `test_without_safe/index.php`: loads Composer autoloader without Safe
30+
31+
Both test files are only loading Composer autoloader (with and without Safe), then echoing "foo".
32+
33+
For each file, you need to install the Composer dependencies:
34+
35+
```bash
36+
cd test_with_safe
37+
composer install
38+
cd ..
39+
cd test_without_safe
40+
composer install
41+
cd ..
42+
```
43+
44+
A `docker-compose.yml` file is provided to start a PHP 7.2 environment with Blackfire enabled.
45+
46+
To start the environment, simply type:
47+
48+
```bash
49+
BLACKFIRE_SERVER_ID=[xyz] BLACKFIRE_SERVER_TOKEN=[abc] docker-compose up
50+
```
51+
52+
You can now browse to `http://localhost:8888/test_with_safe` and `http://localhost:8888/test_without_safe` and profile it using the [Blackfire companion](https://blackfire.io/docs/integrations/firefox)
53+

performance/docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3.3'
2+
services:
3+
php:
4+
image: thecodingmachine/php:7.2-v1-apache
5+
volumes:
6+
- .:/var/www/html
7+
ports:
8+
- "8888:80"
9+
environment:
10+
PHP_EXTENSION_BLACKFIRE: 1
11+
blackfire:
12+
image: blackfire/blackfire
13+
environment:
14+
# Exposes the host BLACKFIRE_SERVER_ID and TOKEN environment variables.
15+
- BLACKFIRE_SERVER_ID
16+
- BLACKFIRE_SERVER_TOKEN
17+
# You can also use global environment credentials :
18+
# BLACKFIRE_SERVER_ID: SERVER-ID
19+
# BLACKFIRE_SERVER_TOKEN: SERVER-TOKEN
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"thecodingmachine/safe": "*"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
// This file imports Safe's Composer autoloader (with all files)
3+
require_once 'vendor/autoload.php';
4+
5+
echo 'foo';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
// This file imports an empty Composer autoloader.
3+
require_once 'vendor/autoload.php';
4+
5+
echo 'foo';

0 commit comments

Comments
 (0)