note 79289 deleted from function.getmypid by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 00:25:17 +0000 |
| Subject: | note 79289 deleted from function.getmypid by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141841@lists.php.net to get a copy of this message | ||
Note Submitter: tugla solonka
----
What is the difference between posix_getpid() and getmypid()? It appears that they're
implemented differently. I wrote this quick test script:
<?php
$max = 1000000;
$arr = array();
$a_0 = microtime(TRUE);
for ($i=0; $i<$max; $i++) {
$arr[] = getmypid();
}
$a_1 = microtime(TRUE);
$arr = array();
$b_0 = microtime(TRUE);
for ($i=0; $i<$max; $i++) {
$arr[] = posix_getpid();
}
$b_1 = microtime(TRUE);
$diff_a = $a_1 - $a_0;
$diff_b = $b_1 - $b_0;
echo "A: $diff_a, B: $diff_b: " . ($diff_b / $diff_a) . "\n";
?>
I ran this a number of times, and time got results similar to this:
A: 1.1289880275726, B: 1.1726188659668: 1.0386459708417
So it's around 4% faster to use getmypid().