note 123258 added to function.hrtime

From: Date: Thu, 25 Oct 2018 12:52:57 +0000
Subject: note 123258 added to function.hrtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-209508@lists.php.net to get a copy of this message
This function is particularly necessary on VMs running on KVM, XEN (openstack, AWS EC2, etc) when timing execution times. On these platforms which lack vDSO the common method of using time() or microtime() can dramatically increase CPU/execution time due to the context switching from userland to kernel when running the gettimeofday() system call. The common pattern is: <?php $time = -microtime(true); sleep(5); $end = sprintf('%f', $time += microtime(true)); ?> Substituted as: <?php $start=hrtime(true); sleep(5); $end=hrtime(true); $eta=$end-$start; echo $eta/1e+6; //nanoseconds to milliseconds //5000.362419 //OR simply $eta=-hrtime(true); sleep(5); $eta+=hrtime(true); echo $eta/1e+6; //nanoseconds to milliseconds //5000.088229 ?> There is also the new StopWatch class http://php.net/manual/en/class.hrtime-stopwatch.php ---- Server IP: 208.43.231.9 Probable Submitter: 50.56.230.4 ---- Manual Page -- http://php.net/manual/en/function.hrtime.php Edit -- https://master.php.net/note/edit/123258 Del: integrated -- https://master.php.net/note/delete/123258/integrated Del: useless -- https://master.php.net/note/delete/123258/useless Del: bad code -- https://master.php.net/note/delete/123258/bad+code Del: spam -- https://master.php.net/note/delete/123258/spam Del: non-english -- https://master.php.net/note/delete/123258/non-english Del: in docs -- https://master.php.net/note/delete/123258/in+docs Del: other reasons-- https://master.php.net/note/delete/123258 Reject -- https://master.php.net/note/reject/123258 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209508) next »