Skip to content

Instantly share code, notes, and snippets.

@adamziel
Last active April 15, 2023 11:06
Show Gist options
  • Save adamziel/f1484c773627577aed75d6e06947cdfd to your computer and use it in GitHub Desktop.
Save adamziel/f1484c773627577aed75d6e06947cdfd to your computer and use it in GitHub Desktop.
Measure performance of php.wasm

Naive benchmark of php.wasm performance

I wrote a simple script that measures how many json_encode("Hello World") it can do in 5 seconds and these are the results:

With php test.php:

Serialized 'Hello World' to JSON 63862450 times in 5 seconds.

With PHP=8.1 npx @php-wasm/cli test.php:

Serialized 'Hello World' to JSON 30654414 times in 5 seconds.

With the interactive code block

Serialized 'Hello World' to JSON 27264540 times in 5 seconds.

In this oversimplified test, WebAssembly PHP is two times slower than the native build. Not bad at all!

<?php
$start_time = microtime(true); // Get the start time
$count = 0; // Set the initial count to 0
while (microtime(true) - $start_time < 5) { // Run the loop for 5 seconds
json_encode("Hello World"); // Serialize "Hello World" to JSON
$count++; // Increment the count
}
echo "Serialized 'Hello World' to JSON $count times in 5 seconds.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment