The Cost of Test Isolation (and other PHPUnit Features)

Sebastian Bergmann » 27 November 2008 » in Articles » 0 Comments

Some of PHPUnit features come with the cost of a performance penality. This posting explores the effect of the --no-syntax-check, $backupGlobals = FALSE;, and --coverage-html options.

Syntax Check: disabled, $GLOBALS Backup: disabled, Code Coverage: disabled

By default, PHPUnit performs a syntax check on the test source files before it loads them. This behaviour can be disabled using the --no-syntax-check option.

Also by default, PHPUnit runs your tests in a way where even changes to global and super-global variables (such as $GLOBALS) do not affect other tests. The backup and restore operations for the global and super-global variables that ensure this behaviour can be disabled by declaring $backupGlobals = FALSE; in a test case class. This was done for the benchmark below.

sb@ubuntu Money % time phpunit --no-syntax-check MoneyTest
PHPUnit 3.3.6-dev by Sebastian Bergmann.

......................

Time: 0 seconds

OK (22 tests, 34 assertions)
phpunit --no-syntax-check MoneyTest
0.16s user 0.08s system 100% cpu 0.235 total
Profiling PHPUnit with Xdebug

Syntax Check: disabled, $GLOBALS Backup: enabled, Code Coverage: disabled

The following benchmark clearly shows the cost of the calls to the serialize() and unserialize() functions that are performed during the backup and restore operations for the global and super-global variables.

sb@ubuntu Money % time phpunit --no-syntax-check MoneyTest
PHPUnit 3.3.6-dev by Sebastian Bergmann.

......................

Time: 0 seconds

OK (22 tests, 34 assertions)
phpunit --no-syntax-check MoneyTest
0.31s user 0.14s system 93% cpu 0.483 total
Profiling PHPUnit with Xdebug

Syntax Check: enabled, $GLOBALS Backup: enabled, Code Coverage: disabled

Although the syntax check of test source files involves the creation of a new PHP process, the slowdown does not look too bad according to the following benchmark.

sb@ubuntu Money % time phpunit MoneyTest
PHPUnit 3.3.6-dev by Sebastian Bergmann.

......................

Time: 0 seconds

OK (22 tests, 34 assertions)
phpunit MoneyTest
0.31s user 0.16s system 95% cpu 0.487 total
Profiling PHPUnit with Xdebug

Syntax Check: enabled, $GLOBALS Backup: enabled, Code Coverage: enabled

The performance penality that comes with code coverage data collection and report generation that we see in the final benchmark has already been discussed previously on this blog here and here.

sb@ubuntu Money % time phpunit --coverage-html /tmp/coverage MoneyTest
PHPUnit 3.3.6-dev by Sebastian Bergmann.

......................

Time: 0 seconds

OK (22 tests, 34 assertions)
Generating code coverage report, this may take a moment.
phpunit --coverage-html /tmp/coverage MoneyTest
0.95s user 0.26s system 95% cpu 1.275 total
Profiling PHPUnit with Xdebug
Defined tags for this entry: , , , ,

Trackback specific URI for this entry

0 Comments to "The Cost of Test Isolation (and other PHPUnit Features)"

Display comments as (Linear | Threaded)
  1. No comments

1 Trackback to "The Cost of Test Isolation (and other PHPUnit Features)"

  1. Sebastian Bergmann 18/01/2009 at 14:36
    This is a follow-up to "The Cost of Test Isolation (and other PHPUnit Features)".Since the previous posting, I have added a backup/restore mechanism for static attributes of classes to PHPUnit. This is yet another feature of PHPUnit that makes the testing

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.