Created
August 12, 2012 08:14
-
-
Save masakielastic/3330620 to your computer and use it in GitHub Desktop.
Benchmark curl_setopt_array vs curl_setopt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function benchmark(callable $block) { | |
$start = microtime(true); | |
for ($i = 0; $i < 100000; ++$i) { | |
$block(); | |
} | |
$end = microtime(true); | |
return $end - $start; | |
} | |
echo 'curl_setopt_array: ', benchmark(function() { | |
$options = array( | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_HTTPHEADER => array('Expect:'), | |
CURLOPT_HEADER => FALSE | |
); | |
$ci = curl_init(); | |
curl_setopt_array($ci, $options); | |
}), PHP_EOL; | |
echo ' curl_setopt: ', benchmark(function() { | |
$ci = curl_init(); | |
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); | |
curl_setopt($ci, CURLOPT_HEADER, FALSE); | |
}), PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl_setopt_array: 1.2236759662628 | |
curl_setopt: 1.384241104126 |
in 2023 with PHP v8.2, it seems that the result has turned around.
although it is true that the times were reduced for the 2:
curl_setopt_array: 0.20178509712219
curl_setopt: 0.17806507110596
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My result on a Skylake CPU:
curl_setopt_array: 0.41492700576782
curl_setopt: 0.42061114311218
So I suppose even the speed is slightly noticeable in my machine.