Skip to content

Instantly share code, notes, and snippets.

@kiler129
Created July 4, 2025 02:55
Show Gist options
  • Save kiler129/c3956396c22163116f38aab332497c5d to your computer and use it in GitHub Desktop.
Save kiler129/c3956396c22163116f38aab332497c5d to your computer and use it in GitHub Desktop.

PHP vs Alpine

TL;DR: Alpine is slow in memory-intensive workloads, like 2x slower...

Bookworm     Alpine   % difference
 1534.76    3449.95        -124.8%
 1724.67    3835.08        -122.4%
 1678.51    3493.07        -108.1%
 1668.49    3542.68        -112.3%
 1721.22    3260.29         -89.4%
 1576.78    3343.49        -112.0%
 1543.26    3753.95        -143.2%
 1872.86    3528.55         -88.4%
 1650.43    3582.40        -117.1%
 1651.82    3459.15        -109.4%
----------------------------------
                Avg diff   -112.7% 

Test script

% cat bench.php
<?php
declare(strict_types=1);

$t = \hrtime(true);
$x = \random_bytes(1_048_576); //1MB
for ($i=0; $i<10_000; ++$i) {
  $y = \str_replace('a', 'b', $x);
}
echo round((\hrtime(true)-$t)/1**8, 2) . "ms\n";

Linux Docker w/Bookworm

% docker run -it --rm -v "$(pwd)/bench.php:/bench.php:ro" php:8.4-cli-bookworm sh -c 'for i in $(seq 10); do php bench.php; done'
1534.76 ms
1724.67 ms
1678.51 ms
1668.49 ms
1721.22 ms
1576.78 ms
1543.26 ms
1872.86 ms
1650.43 ms
1651.82 ms

Linux Docker w/Alpine

% docker run -it --rm -v "$(pwd)/bench.php:/bench.php:ro" php:8.4-cli-alpine sh -c 'for i in $(seq 10); do php bench.php; done'
3449.95 ms
3835.08 ms
3493.07 ms
3542.68 ms
3260.29 ms
3343.49 ms
3753.95 ms
3528.55 ms
3582.4 ms
3459.15 ms

macOS native

% for i in $(seq 10); do php bench.php; done
1862.53 ms
1882.49 ms
1892.7 ms
1867.39 ms
1847.61 ms
1902.77 ms
1899.33 ms
1914.35 ms
1866.69 ms
1868.3 ms

macOS Docker w/Bookworm

% docker run -it --rm -v "$(pwd)/bench.php:/bench.php:ro" php:8.4-cli-bookworm sh -c 'for i in $(seq 10); do php bench.php; done'
2932.98 ms
2966.92 ms
2882.26 ms
2979.35 ms
2900.03 ms
2881.9 ms
2900.26 ms
2890.4 ms
2888.33 ms
2864.92 ms

macOS Docker w/Alpine

% docker run -it --rm -v "$(pwd)/bench.php:/bench.php:ro" php:8.4-cli-alpine sh -c 'for i in $(seq 10); do php bench.php; done'
3134.83 ms
3161.5 ms
3149.2 ms
3147.06 ms
3129.06 ms
3136.63 ms
3097.87 ms
3168.91 ms
3135.04 ms
3115.18 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment