Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpunit tests run using PHP7.2 and 7.1 are 3x slower than when run using PHP7.0

If I run my tests using PHP7.2 or PHP7.1 they are about 3x slower than if I run them using PHP7.0. Is there anyway to get to the bottom of why this is happening?

Even when I run the test suites (Feature & Unit) separately I still see the slow down. It's only when I run the tests individually does the speed difference become insignificant.

I'm using Laravel 5.5.20 and Laravel Homestead 7.0.1. I have 47 rather simple tests, some hitting the database, others just simple assertions; so there isn't anything that should take ages.

I installed johnkary/phpunit-speedtrap to see which tests take the longest so I could remove those but there isn't a specific test that takes a long time because if I remove the offending test, the next one will take ages (see below).

First Run                Second Run
Test A    0.2 sec        Test A    0.2 sec
Test B.   0.3 sec        Test B.   0.3 sec
Test C    0.1 sec        Test C    0.1 sec
Test D    0.1 sec        Test D    0.1 sec
Test E    9.3 sec        REMOVED Test E
Test F    0.3 sec        Test F    9.3 sec <-- Test F now takes ages
Test G    0.2 sec        Test G    0.2 sec

I am also using an in-memory SQLite3 database, with the Laravel CreatesApplication and RefreshDatabase trait as I want each test to run independently.

I do not have Xdebug installed or running. Is there something known that PHP7.1 and PHP7.2 take a long time to run PHPUnit tests? Is there something else I can install (or even run it with Xdebug) to track down what exactly it is that is causing the issue?

Setup

Laravel 5.5.20
Laravel Homestead 7.0.1 (Per-project installation)
PHPUnit 6.4.4
Vagrant 2.0.1
Virtualbox 5.2.4

Results

PHP 7.2 PHPUnit 6.4.4
Time: 12.4 seconds, Memory: 162.00MB

PHP 7.1 PHPUnit 6.4.4
Time: 12.19 seconds, Memory: 162.00MB

PHP 7.0 PHPUnit 6.4.4
Time: 4.88 seconds, Memory: 162.00MB
like image 436
Michael Avatar asked Jan 14 '18 11:01

Michael


1 Answers

I had the same issue as you but with XDebug installed. I found a pretty good hint by a user named Roni on Laracasts (I can't find the link anymore, sorry) which says to run tests with the -n flag of the php command, like this: php -n vendor/bin/phpunit.

According to the documentation at php.net (command line options) this is for running the command without what php.ini is defining. Which means no includes of extensions.

-n No php.ini file will be used

So, for me it runs tests in a minute now, not in 15 minutes. The problem is kind of strange, because it began with php 7.2 on my machine but others in my team don't have the issue, despite the fact that xdebug is installed. I wonder what really is behind this issue.

like image 127
Michael K. Avatar answered Nov 17 '22 05:11

Michael K.