note 79289 added to function.getmypid
| From: | tuglasolonka at osu1 dot php dot net | Date: | Mon, 19 Nov 2007 22:09:07 +0000 |
| Subject: | note 79289 added to function.getmypid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132412@lists.php.net to get a copy of this message | ||
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().
----
Server IP: 69.147.83.197
Probable Submitter: 152.160.38.65
----
Manual Page -- http://www.php.net/manual/en/function.getmypid.php
Edit -- https://master.php.net/note/edit/79289
Del: integrated -- https://master.php.net/note/delete/79289/integrated
Del: useless -- https://master.php.net/note/delete/79289/useless
Del: bad code -- https://master.php.net/note/delete/79289/bad+code
Del: spam -- https://master.php.net/note/delete/79289/spam
Del: non-english -- https://master.php.net/note/delete/79289/non-english
Del: in docs -- https://master.php.net/note/delete/79289/in+docs
Del: other reasons-- https://master.php.net/note/delete/79289
Reject -- https://master.php.net/note/reject/79289
Search -- https://master.php.net/manage/user-notes.php