Skip to content

Instantly share code, notes, and snippets.

@imanghafoori1
Created July 31, 2019 19:56
Show Gist options
  • Save imanghafoori1/a9f672a9cc0a693737a75612822c3b82 to your computer and use it in GitHub Desktop.
Save imanghafoori1/a9f672a9cc0a693737a75612822c3b82 to your computer and use it in GitHub Desktop.
compare type hint performance hit
<?php
function a1(int $a,int $b) : int {
return $a + $b;
}
function a2( $a, $b){
return $a + $b;
}
$f = microtime(true);
for($a = 0; $a<100000; $a++) {
a1(1, 1);
}
echo microtime(true) - $f;
$f = microtime(true);
for($a = 0; $a<100000; $a++) {
a2(1, 1);
}
echo ' - without type-hint: ';
echo microtime(true) - $f;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment