Skip to content

Instantly share code, notes, and snippets.

@postpersonality
Created January 28, 2016 14:25
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 postpersonality/11f673d1265dce993c43 to your computer and use it in GitHub Desktop.
Save postpersonality/11f673d1265dce993c43 to your computer and use it in GitHub Desktop.
// Benchmark params
$runs = 100000000;
// Gen test array
$strMatch = 'test string';
echo 'Benchmark runs: ' . $runs . PHP_EOL;
// Benchmark isset
$timeStart = microtime(true);
for ($i = 0; $i < $runs; $i++) {
$strMatch === "test string";
}
echo 'double quotes: ' . (microtime(true) - $timeStart) . PHP_EOL;
// Benchmark array_key_exist
$timeStart = microtime(true);
for ($i = 0; $i < $runs; $i++) {
$strMatch === 'test string';
}
echo 'single quotes: ' . (microtime(true) - $timeStart) . PHP_EOL;
@postpersonality
Copy link
Author

Benchmark runs: 100000000 double quotes: 11.21027803421 single quotes: 11.260735034943
Benchmark runs: 100000000 double quotes: 11.485301971436 single quotes: 11.39031291008
Benchmark runs: 100000000 double quotes: 11.485301971436 single quotes: 11.39031291008

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment