diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5050f096..96ba17e1 100755 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -19,4 +19,4 @@ jobs: - name: Run codestyle sniffer run: composer run-script codestyle - name: Run benchmark - run: php tests/benchmark.php + run: php tests/benchmarks/run.php diff --git a/tests/benchmark.php b/tests/benchmark.php deleted file mode 100644 index 054b6a81..00000000 --- a/tests/benchmark.php +++ /dev/null @@ -1,23 +0,0 @@ -> 10; - -echo "Memory: $memory_used KB\n"; -echo "Time: $time ms\n"; diff --git a/tests/benchmark-mocks.php b/tests/benchmarks/mocks.php similarity index 89% rename from tests/benchmark-mocks.php rename to tests/benchmarks/mocks.php index e025143c..fbd423c2 100644 --- a/tests/benchmark-mocks.php +++ b/tests/benchmarks/mocks.php @@ -5,7 +5,7 @@ * phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace */ -define('ABSPATH', dirname(__DIR__, 1)); +define('ABSPATH', dirname(__DIR__, 2)); define('HOUR_IN_SECONDS', 3600); $options = []; @@ -147,24 +147,29 @@ function is_wp_error($thing) return false; } -function __($string, $text_domain) +function __($text, $domain) { - return $string; + return $text; } -function register_post_type($name, $args) +function _e($text, $domain) { + echo $text; } -function wp_register_script($handle, $src, $deps = [], $version = '') +function register_post_type() { } -function plugins_url($file, $path) +function wp_register_script($handle, $src, $deps = [], $in_footer = true) { - return $path; } +function plugins_url($path, $plugin = '') +{ +} + + class wpdb_mock { public $prefix = ''; diff --git a/tests/benchmarks/plugin.php b/tests/benchmarks/plugin.php new file mode 100644 index 00000000..0482e2d2 --- /dev/null +++ b/tests/benchmarks/plugin.php @@ -0,0 +1,33 @@ +> 10; + +header("Content-Type: application/json"); +echo json_encode(['memory' => $memory_used, 'time' => $time]); diff --git a/tests/benchmarks/run.php b/tests/benchmarks/run.php new file mode 100755 index 00000000..ff369f13 --- /dev/null +++ b/tests/benchmarks/run.php @@ -0,0 +1,59 @@ +memory; + $times[] = $data->time; + } + + [$time_min, $time_mean, $time_max] = analyze($times); + + echo $opcache ? "with opcache: " : "without opcache: "; + echo "min: $time_min\tmean: $time_mean\tmax: $time_max\n"; +} + +$root = __DIR__; +$ph = popen("php -S localhost:8080 -q -t {$root} &2>/dev/null", "r"); +if (!$ph) { + echo "Error starting HTTP server\n"; + exit(1); +} +sleep(2); + +bench(100, true); +bench(100, false); + +pclose($ph);