Skip to content

Instantly share code, notes, and snippets.

@jscaltreto
Created January 28, 2019 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jscaltreto/8f6adf38e7abb08a831ef37b84c14ace to your computer and use it in GitHub Desktop.
Save jscaltreto/8f6adf38e7abb08a831ef37b84c14ace to your computer and use it in GitHub Desktop.
Demo of finfo performance in php 7.2 vs 7.3
#!/bin/bash
set -e
ITERS=${1:-1000}
echo "Testing finfo over $ITERS iterations"
for VER in '7.2' '7.3'; do
echo ---
echo "Testing PHP $VER"
docker run -i \
-e "ITERS=${ITERS}" \
php:${VER}-cli-alpine php <<'EOF'
<?php
$iters = $_ENV["ITERS"];
$start = microtime(true);
for ($i = 1; $i <= $iters; $i++){
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file("/bin/sh");
unset($finfo);
}
$ttl = microtime(true) - $start;
echo "Took: $ttl\n";
?>
EOF
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment