{"id":373,"date":"2023-08-21T12:13:42","date_gmt":"2023-08-21T12:13:42","guid":{"rendered":"https:\/\/wp-yoda.com\/en\/?p=373"},"modified":"2023-09-12T19:59:33","modified_gmt":"2023-09-12T19:59:33","slug":"speed-up-phpunit-code-coverage-with-pcov","status":"publish","type":"post","link":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/","title":{"rendered":"Speed up PHPUnit Code Coverage with PCOV"},"content":{"rendered":"\n<p><strong>PCOV<\/strong> is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It can be used to collect information about code coverage lines during testing.<\/p>\n\n\n\n<p><strong>Its main advantage<\/strong> over other code coverage analysis tools is its speed. It works faster and uses fewer resources.<\/p>\n\n\n  \r\n    \r\n<div id=\"wpj-jtoc\" class=\"wpj-jtoc wpj-jtoc--main --jtoc-the-content --jtoc-theme-basic-light --jtoc-title-align-left --jtoc-toggle-icon --jtoc-toggle-position-right --jtoc-toggle-1 --jtoc-has-numeration --jtoc-numeration-legacy --jtoc-has-custom-styles --jtoc-is-unfolded --jtoc-align-left\" >\r\n  <!-- TOC -->\r\n        <div class=\"wpj-jtoc--toc wpj-jtoc--toc-inline \" >\r\n              <div class=\"wpj-jtoc--header\">\r\n        <div class=\"wpj-jtoc--header-main\">\r\n                    <div class=\"wpj-jtoc--title\">\r\n                        <span class=\"wpj-jtoc--title-label\">Table of contents<\/span>\r\n          <\/div>\r\n                                <div class=\"wpj-jtoc--toggle-wrap\">\r\n                                                          <div class=\"wpj-jtoc--toggle-box\">\r\n                  <div class=\"wpj-jtoc--toggle\"><\/div>\r\n                <\/div>\r\n                          <\/div>\r\n                  <\/div>\r\n      <\/div>\r\n            <div class=\"wpj-jtoc--body\">\r\n            <nav class=\"wpj-jtoc--nav\">\r\n        <ol class=\"wpj-jtoc--items\"><li class=\"wpj-jtoc--item --jtoc-h2\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h2\" data-depth=\"2\">\r\n                                                <a href=\"#about-pcov\"  title=\"About PCOV\" data-numeration=\"1\">About PCOV<\/a>\r\n                    <\/div><\/li><li class=\"wpj-jtoc--item --jtoc-h2\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h2\" data-depth=\"2\">\r\n                                                <a href=\"#comparison-of-pcov-and-xdebug\"  title=\"Comparison of PCOV and Xdebug\" data-numeration=\"2\">Comparison of PCOV and Xdebug<\/a>\r\n                    <\/div><ol class=\"wpj-jtoc--items\"><li class=\"wpj-jtoc--item --jtoc-h3\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h3\" data-depth=\"3\">\r\n                                                <a href=\"#about-the-test-bench\"  title=\"About the test bench\" data-numeration=\"2.1\">About the test bench<\/a>\r\n                    <\/div><\/li><li class=\"wpj-jtoc--item --jtoc-h3\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h3\" data-depth=\"3\">\r\n                                                <a href=\"#performance-test-on-php-82\"  title=\"Performance test on PHP 8.2\" data-numeration=\"2.2\">Performance test on PHP 8.2<\/a>\r\n                    <\/div><ol class=\"wpj-jtoc--items\"><li class=\"wpj-jtoc--item --jtoc-h4\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h4\" data-depth=\"4\">\r\n                                                <a href=\"#pcov\"  title=\"PCOV\" data-numeration=\"2.2.1\">PCOV<\/a>\r\n                    <\/div><\/li><li class=\"wpj-jtoc--item --jtoc-h4\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h4\" data-depth=\"4\">\r\n                                                <a href=\"#xdebug-32\"  title=\"Xdebug 3.2\" data-numeration=\"2.2.2\">Xdebug 3.2<\/a>\r\n                    <\/div><\/li><\/ol><\/li><li class=\"wpj-jtoc--item --jtoc-h3\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h3\" data-depth=\"3\">\r\n                                                <a href=\"#performance-test-on-php-74\"  title=\"Performance test on PHP 7.4\" data-numeration=\"2.3\">Performance test on PHP 7.4<\/a>\r\n                    <\/div><ol class=\"wpj-jtoc--items\"><li class=\"wpj-jtoc--item --jtoc-h4\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h4\" data-depth=\"4\">\r\n                                                <a href=\"#pcov_1\"  title=\"PCOV\" data-numeration=\"2.3.1\">PCOV<\/a>\r\n                    <\/div><\/li><li class=\"wpj-jtoc--item --jtoc-h4\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h4\" data-depth=\"4\">\r\n                                                <a href=\"#xdebug-31\"  title=\"Xdebug 3.1\" data-numeration=\"2.3.2\">Xdebug 3.1<\/a>\r\n                    <\/div><\/li><li class=\"wpj-jtoc--item --jtoc-h4\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h4\" data-depth=\"4\">\r\n                                                <a href=\"#xdebug-29\"  title=\"Xdebug 2.9\" data-numeration=\"2.3.3\">Xdebug 2.9<\/a>\r\n                    <\/div><\/li><\/ol><\/li><li class=\"wpj-jtoc--item --jtoc-h3\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h3\" data-depth=\"3\">\r\n                                                <a href=\"#test-results\"  title=\"Test results\" data-numeration=\"2.4\">Test results<\/a>\r\n                    <\/div><\/li><\/ol><\/li><li class=\"wpj-jtoc--item --jtoc-h2\">\r\n        <div class=\"wpj-jtoc--item-content --jtoc-h2\" data-depth=\"2\">\r\n                                                <a href=\"#conclusion\"  title=\"Conclusion\" data-numeration=\"3\">Conclusion<\/a>\r\n                    <\/div><\/li><\/ol>      <\/nav>\r\n          <\/div>\r\n      <\/div>\r\n    <\/div>\r\n\n\n\n<h2 class=\"wp-block-heading\">About PCOV<\/h2>\n\n\n\n<p>PCOV was created by Joe Watkins solely focused on code coverage functionality without the additional features (profiling, tracing) found in other tools such as Xdebug and PHPDBG. This approach improves performance and speeds up testing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comparison of PCOV and Xdebug<\/h2>\n\n\n\n<p>PCOV and Xdebug are two different PHP tools used primarily for different tasks. However, both tools can be used to analyze code coverage when testing through PHPUnit.<\/p>\n\n\n\n<p>With PCOV we can collect information about line coverage, while with Xdebug we have line, branch and path coverage. Read more about coverage types <a href=\"https:\/\/docs.phpunit.de\/en\/10.0\/code-coverage.html#software-metrics-for-code-coverage\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">at the link<\/a>.<\/p>\n\n\n\n<p><strong>PCOV has several advantages over Xdebug:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\" style=\"margin-top:var(--wp--preset--spacing--20);margin-right:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);margin-left:var(--wp--preset--spacing--20)\">\n<li>Faster while running Code Coverage 2-4 times.<\/li>\n\n\n\n<li>Consumes fewer resources.<\/li>\n<\/ul>\n\n\n\n<p><strong>The disadvantages of PCOV over Xdebug include the following:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\" style=\"margin-top:var(--wp--preset--spacing--20);margin-right:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);margin-left:var(--wp--preset--spacing--20)\">\n<li>Does not support <a href=\"https:\/\/docs.phpunit.de\/en\/10.0\/code-coverage.html#software-metrics-for-code-coverage\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">path coverage and branch coverage<\/a>.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote has-highlight-light-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-large-font-size\">Impact on PHP performance<\/p>\n\n\n\n<p>PCOV has an impact on PHP performance when enabled. The performance impact is not such as noticeable as Xdebug, but you may encounter it when doing static analysis or running linter.<br>Activate it only for code coverage in the GitHub workflow with test runs or when running Code Coverage.<\/p>\n\n\n\n<p>You can use the following command to activate it before running:<br><code>php -dpcov.enabled=1 .\/vendor\/bin\/phpunit --coverage-text<\/code><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-highlight-light-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-large-font-size\">UPD: PHPUnit errors in Code Coverage mode below version 9.5.20 when using @runInSeparateProcess<\/p>\n\n\n\n<p>When using PHPUnit versions below <code>9.5.20<\/code> in Code Coverage mode with PCOV, if you run PCOV immediately before running Code Coverage, you may encounter errors in tests that use the <code>@runInSeparateProcess<\/code> annotation (<em>which means run the test in a separate process<\/em>):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nPHP Fatal error:  Uncaught SebastianBergmann\\CodeCoverage\\NoCodeCoverageDriverAvailableException: No code coverage driver available in \/var\/www\/html\/vendor\/phpunit\/php-code-coverage\/src\/Driver\/Selector.php:53\nStack trace:\n#0 Standard input code(423): SebastianBergmann\\CodeCoverage\\Driver\\Selector-&gt;forLineCoverage(Object(SebastianBergmann\\CodeCoverage\\Filter))\n#1 Standard input code(1192): __phpunit_run_isolated_test()\n#2 {main}\n  thrown in \/var\/www\/html\/vendor\/phpunit\/php-code-coverage\/src\/Driver\/Selector.php on line 53\nFatal error: Uncaught SebastianBergmann\\CodeCoverage\\NoCodeCoverageDriverAvailableException: No code coverage driver available in \/var\/www\/html\/vendor\/phpunit\/php-code-coverage\/src\/Driver\/Selector.php:53\nStack trace:\n#0 Standard input code(423): SebastianBergmann\\CodeCoverage\\Driver\\Selector-&gt;forLineCoverage(Object(SebastianBergmann\\CodeCoverage\\Filter))\n#1 Standard input code(1192): __phpunit_run_isolated_test()\n#2 {main}\n  thrown in \/var\/www\/html\/vendor\/phpunit\/php-code-coverage\/src\/Driver\/Selector.php on line 53\n<\/pre><\/div>\n\n\n<p>This error tells us that the Code Coverage driver is missing and the <code>phpunit\/php-code-coverage<\/code>  package does not see it when running an isolated test.<\/p>\n\n\n\n<p>This begs the question: Why doesn&#8217;t PHPUnit see the driver? Because we activate PCOV just before running Code Coverage.<br><br>The answer is that in PHPUnit before <code>9.5.20<\/code>, the flags with which the PHP script was run were not passed to child processes spawned by PHPUnit Code Coverage. This means that the child processes are running with the PCOV driver disabled. For more details you can visit the <a href=\"https:\/\/github.com\/sebastianbergmann\/phpunit\/issues\/4664\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">issue on GitHub<\/a>.<\/p>\n\n\n\n<p>There are two solutions:<\/p>\n\n\n\n<ol class=\"wp-block-list\" style=\"margin-top:0;margin-right:0;margin-bottom:0;margin-left:0\">\n<li>Update PHPUnit to <code>9.5.20<\/code> to include an updated version of the Code Coverage package with the fixed issue.<\/li>\n\n\n\n<li>If you cannot upgrade to <code>9.5.20<\/code> for some reason, you need to activate PCOV in <code>php.ini<\/code> for the entire server in which you are running Code Coverage.<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-highlight-light-background-color has-background is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Compatibility<\/p>\n<cite>PCOV and Xdebug overload the same parts of the PHP engine, and as a result they are not compatible to work together.<br>If you need to use Xdebug for debugging or profiling, then you will need to disable PCOV and vice versa.<\/cite><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">About the test bench<\/h3>\n\n\n\n<p>For the tests, I used the Laravel project <a href=\"https:\/\/github.com\/BookStackApp\/BookStack\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">BookStack<\/a>. The test suite of the project has <code>950 tests, 4578 assertions<\/code> and includes UnitTests and IntegrationTests. This set is more than enough to see the performance difference between PCOV and Xdebug.<\/p>\n\n\n\n<p>All tests were run in GitHub Actions. BookStack already contains a customized isolated workflow for the tests. From test to test, I changed the coverage driver and PHP version in the <code>shivammathur\/setup-php@v2<\/code> GitHub Actions settings.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>Each test was performed 3 times and the mean values were chosen for the article.<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>Test execution times are given in minutes.<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>The tests used PCOV version 1.0 on PHP 8.2 and 7.4<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>The commit on which the tests were performed <code>6e6f1133<\/code> in the BookStack repository.<\/cite><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Performance test on PHP 8.2<\/h3>\n\n\n\n<p>Let&#8217;s take a look at the difference in performance and resource consumption between PCOV and Xdebug on PHP 8.2.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">PCOV<\/h4>\n\n\n\n<p>During the tests I got the following results<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nTime: 02:00, Memory: 184.50 MB\n<\/pre><\/div>\n\n\n<p>2 mitutes is pretty good for <code>950 tests \u0438 4578 asserts<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png\"><img decoding=\"async\" src=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30-1024x474.png\" alt=\"PCOV performance test in code coverage mode on PHP 8.2\" class=\"wp-image-1849\"\/><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Xdebug 3.2<\/h4>\n\n\n\n<p>Xdebug 3.2 was optimized quite well to reduce overhead. But Xdebug&#8217;s execution time is 2 times worse than PCOV&#8217;s. The difference in memory consumption is ~2mb, which is insignificant.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nTime: 03:55, Memory: 186.50 MB\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-29-1024x481.png\" alt=\"Xdebug 3.2 performance test in code coverage mode on PHP 8.2\" class=\"wp-image-1848\" width=\"765\" height=\"359\"\/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Performance test on PHP 7.4<\/h3>\n\n\n\n<p>PHP 7.4 is unsupported since November 28, 2022, but there are many projects that have not yet migrated to 8+ versions and for these projects the following tests may be useful.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">PCOV<\/h4>\n\n\n\n<p>In tests on PHP 7.4 it showed the same execution time as PHP 8.2, but the memory consumption value is 2 times higher than PHP 8.2.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>The difference in memory consumption in the tests for PHP 7.4 is due to optimizations made for PHP 8.* versions.<\/cite><\/blockquote>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nTime: 02:00, Memory: 347.00 MB\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-21.png\"><img decoding=\"async\" src=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-21-1024x468.png\" alt=\"PCOV performance on PHP 7.4 vs Xdebug\" class=\"wp-image-1813\"\/><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Xdebug 3.1<\/h4>\n\n\n\n<p>Xdebug 3.1 is slower by 2.5 times compared to PCOV on PHP 7.4. The difference in memory is again insignificant ~6mb.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nTime: 04:56, Memory: 353.00 MB\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-25.png\"><img decoding=\"async\" src=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-25-1024x485.png\" alt=\"Xdebug 3.1 performance on PHP 7.4 vs PCOV\" class=\"wp-image-1827\"\/><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Xdebug 2.9<\/h4>\n\n\n\n<p>Of course, I don&#8217;t recommend you to use Xdebug version 2, because it is very slow. But let&#8217;s see what the results are in case you still use this version.<\/p>\n\n\n\n<p>Tests have shown that <strong>Xdebug 2.9 is 4 times slower<\/strong> than PCOV on PHP 7.4.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nTime: 07:59, Memory: 355.00 MB\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-24.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-24-1024x478.png\" alt=\"Xdebug 2.9 performance on PHP 7.4 vs PCOV\" class=\"wp-image-1816\" width=\"764\" height=\"356\"\/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Test results<\/h3>\n\n\n\n<p>Code Coverage test summary table:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Code Coverage Driver<\/td><td class=\"has-text-align-center\" data-align=\"center\">PHP<\/td><td class=\"has-text-align-right\" data-align=\"right\">Time<\/td><td class=\"has-text-align-right\" data-align=\"right\">Memory<\/td><\/tr><tr><td>PCOV<\/td><td class=\"has-text-align-center\" data-align=\"center\">8.2<\/td><td class=\"has-text-align-right\" data-align=\"right\">02:00<\/td><td class=\"has-text-align-right\" data-align=\"right\">184.50 MB<\/td><\/tr><tr><td>PCOV<\/td><td class=\"has-text-align-center\" data-align=\"center\">7.4<\/td><td class=\"has-text-align-right\" data-align=\"right\">02:00<\/td><td class=\"has-text-align-right\" data-align=\"right\">347.00 MB<\/td><\/tr><tr><td>Xdebug 3.2<\/td><td class=\"has-text-align-center\" data-align=\"center\">8.2<\/td><td class=\"has-text-align-right\" data-align=\"right\">03:56<\/td><td class=\"has-text-align-right\" data-align=\"right\">186.50 MB<\/td><\/tr><tr><td>Xdebug 3.1 <\/td><td class=\"has-text-align-center\" data-align=\"center\">7.4<\/td><td class=\"has-text-align-right\" data-align=\"right\">04:56<\/td><td class=\"has-text-align-right\" data-align=\"right\">353.00 MB<\/td><\/tr><tr><td>Xdebug 2.9<\/td><td class=\"has-text-align-center\" data-align=\"center\">7.4<\/td><td class=\"has-text-align-right\" data-align=\"right\">07:59<\/td><td class=\"has-text-align-right\" data-align=\"right\">355.00 MB<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>As you can see:<\/p>\n\n\n\n<ul class=\"wp-block-list\" style=\"margin-top:var(--wp--preset--spacing--20);margin-right:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);margin-left:var(--wp--preset--spacing--20)\">\n<li>PCOV is faster than Xdebug 3.2 (<em>PHP 8.2<\/em>) by 197%<\/li>\n\n\n\n<li>PCOV is faster than Xdebug 3.1 (PHP 7.4) by 247%<\/li>\n\n\n\n<li>PCOV is faster than Xdebug 2.9 (PHP 7.4) by 400%<\/li>\n\n\n\n<li>Xdebug 3.2 (PHP 8.2) is 25% faster than Xdebug 3.1 (PHP 7.4).<\/li>\n\n\n\n<li>Xdebug 3.1 is 60% faster than Xdebug 2.9 (PHP 7.4).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>PCOV beats Xdebug in speed of execution of tests with code coverage by 2-4 times. This may not be significant if you use unit tests that take seconds to execute. But what if your project has also integration tests with a set of <code>5000 tests, 40000 assertions<\/code>, which takes from 5 minutes to complete?<\/p>\n\n\n\n<p>In this case, the performance difference of 2-4 times between PCOV and Xdebug can be significant and it can affect the speed of CI\/CD and the frequency of running tests by the programmer and therefore the speed of development new features due to fixing bugs at a late stage.<\/p>\n\n\n\n<p>It is also important to remember that PCOV, like Xdebug, can affect application performance. Activate it only for code coverage in the GitHub test workflow or just before executing tests.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It can be used to collect information about code coverage lines during testing.<br \/>\nIts main advantage over other code coverage analysis tools is &#8230;<\/p>\n","protected":false},"author":1,"featured_media":375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,30],"tags":[27,29],"class_list":["post-373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-phpunit","tag-codecoverage","tag-phpunit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Speed up PHPUnit Code Coverage with PCOV - WP Yoda<\/title>\n<meta name=\"description\" content=\"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Speed up PHPUnit Code Coverage with PCOV - WP Yoda\" \/>\n<meta property=\"og:description\" content=\"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Yoda\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-21T12:13:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-12T19:59:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1958\" \/>\n\t<meta property=\"og:image:height\" content=\"1104\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/\"},\"author\":{\"name\":\"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#\\\/schema\\\/person\\\/195c797aee113d174e07e4887a9fe464\"},\"headline\":\"Speed up PHPUnit Code Coverage with PCOV\",\"datePublished\":\"2023-08-21T12:13:42+00:00\",\"dateModified\":\"2023-09-12T19:59:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/\"},\"wordCount\":989,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wp-yoda.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-30.png\",\"keywords\":[\"CodeCoverage\",\"PHPUnit\"],\"articleSection\":[\"PHP\",\"PHPUnit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/\",\"url\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/\",\"name\":\"Speed up PHPUnit Code Coverage with PCOV - WP Yoda\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wp-yoda.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-30.png\",\"datePublished\":\"2023-08-21T12:13:42+00:00\",\"dateModified\":\"2023-09-12T19:59:33+00:00\",\"description\":\"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#primaryimage\",\"url\":\"https:\\\/\\\/wp-yoda.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-30.png\",\"contentUrl\":\"https:\\\/\\\/wp-yoda.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-30.png\",\"width\":1958,\"height\":1104,\"caption\":\"Speed up PHPUnit Code Coverage with PCOV\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/php\\\/speed-up-phpunit-code-coverage-with-pcov\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Speed up PHPUnit Code Coverage with PCOV\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/\",\"name\":\"WP Yoda\",\"description\":\"Notes about PHP, WordPress and IT\",\"publisher\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#organization\",\"name\":\"WP Yoda\",\"url\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/05\\\/Andrew_222_Master_Yoda__WordPress_plain_background_763a84a4-5042-4fac-9bdb-4562c05563e7.png\",\"contentUrl\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/05\\\/Andrew_222_Master_Yoda__WordPress_plain_background_763a84a4-5042-4fac-9bdb-4562c05563e7.png\",\"width\":1024,\"height\":1024,\"caption\":\"WP Yoda\"},\"image\":{\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/#\\\/schema\\\/person\\\/195c797aee113d174e07e4887a9fe464\",\"name\":\"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g\",\"caption\":\"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439\"},\"sameAs\":[\"https:\\\/\\\/wp-yoda.com\"],\"url\":\"https:\\\/\\\/wp-yoda.com\\\/en\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Speed up PHPUnit Code Coverage with PCOV - WP Yoda","description":"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/","og_locale":"en_US","og_type":"article","og_title":"Speed up PHPUnit Code Coverage with PCOV - WP Yoda","og_description":"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.","og_url":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/","og_site_name":"WP Yoda","article_published_time":"2023-08-21T12:13:42+00:00","article_modified_time":"2023-09-12T19:59:33+00:00","og_image":[{"width":1958,"height":1104,"url":"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png","type":"image\/png"}],"author":"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439","twitter_card":"summary_large_image","twitter_misc":{"Written by":"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#article","isPartOf":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/"},"author":{"name":"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439","@id":"https:\/\/wp-yoda.com\/en\/#\/schema\/person\/195c797aee113d174e07e4887a9fe464"},"headline":"Speed up PHPUnit Code Coverage with PCOV","datePublished":"2023-08-21T12:13:42+00:00","dateModified":"2023-09-12T19:59:33+00:00","mainEntityOfPage":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/"},"wordCount":989,"commentCount":0,"publisher":{"@id":"https:\/\/wp-yoda.com\/en\/#organization"},"image":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#primaryimage"},"thumbnailUrl":"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png","keywords":["CodeCoverage","PHPUnit"],"articleSection":["PHP","PHPUnit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/","url":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/","name":"Speed up PHPUnit Code Coverage with PCOV - WP Yoda","isPartOf":{"@id":"https:\/\/wp-yoda.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#primaryimage"},"image":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#primaryimage"},"thumbnailUrl":"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png","datePublished":"2023-08-21T12:13:42+00:00","dateModified":"2023-09-12T19:59:33+00:00","description":"PCOV is a PHP driver used in PHPUnit for code coverage, similar to Xdebug or PHPDBG. It is used to collect information about code coverage lines.","breadcrumb":{"@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#primaryimage","url":"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png","contentUrl":"https:\/\/wp-yoda.com\/wp-content\/uploads\/2023\/08\/image-30.png","width":1958,"height":1104,"caption":"Speed up PHPUnit Code Coverage with PCOV"},{"@type":"BreadcrumbList","@id":"https:\/\/wp-yoda.com\/en\/php\/speed-up-phpunit-code-coverage-with-pcov\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wp-yoda.com\/en\/"},{"@type":"ListItem","position":2,"name":"Speed up PHPUnit Code Coverage with PCOV"}]},{"@type":"WebSite","@id":"https:\/\/wp-yoda.com\/en\/#website","url":"https:\/\/wp-yoda.com\/en\/","name":"WP Yoda","description":"Notes about PHP, WordPress and IT","publisher":{"@id":"https:\/\/wp-yoda.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wp-yoda.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/wp-yoda.com\/en\/#organization","name":"WP Yoda","url":"https:\/\/wp-yoda.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wp-yoda.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/wp-yoda.com\/en\/wp-content\/uploads\/sites\/2\/2023\/05\/Andrew_222_Master_Yoda__WordPress_plain_background_763a84a4-5042-4fac-9bdb-4562c05563e7.png","contentUrl":"https:\/\/wp-yoda.com\/en\/wp-content\/uploads\/sites\/2\/2023\/05\/Andrew_222_Master_Yoda__WordPress_plain_background_763a84a4-5042-4fac-9bdb-4562c05563e7.png","width":1024,"height":1024,"caption":"WP Yoda"},"image":{"@id":"https:\/\/wp-yoda.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/wp-yoda.com\/en\/#\/schema\/person\/195c797aee113d174e07e4887a9fe464","name":"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d3f11053e005f02e0dc3049c010b45034646963c7af8edac8076c3767022d750?s=96&r=g","caption":"\u0410\u043d\u0434\u0440\u0435\u0439 \u041f\u0438\u0441\u0430\u0440\u0435\u0432\u0441\u043a\u0438\u0439"},"sameAs":["https:\/\/wp-yoda.com"],"url":"https:\/\/wp-yoda.com\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":0,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/media\/375"}],"wp:attachment":[{"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp-yoda.com\/en\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}