HomePhabricator

Add a convenience function for computing elapsed microtime deltas

Description

Add a convenience function for computing elapsed microtime deltas

Summary:
See D19780. We have a reasonable amount of 1000000 * ($t_end - $t_start) stuff in the codebase that we could simplify. In particular, it would be easy to have too many or too few 0s somewhere and escape notice.

I landed on this method signature instead of phutil_microseconds_between(x, y) since I think it would be hard to remember if parameter order is start, end (chronological) or end, start (like arithmetic subtraction). It should be a little simpler to use in most cases, too.

Test Plan:

$ cat test.php
<?php

require_once 'scripts/init/init-script.php';

$start = microtime(true);

sleep(1);

echo phutil_microseconds_since($start);
echo "\n";
$ php -f test.php
1001921

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19796

Details

Provenance
epriestleyAuthored on Nov 8 2018, 2:09 PM
epriestleyPushed on Nov 8 2018, 8:51 PM
Reviewer
amckinley
Differential Revision
D19796: Add a convenience function for computing elapsed microtime deltas
Parents
rPHUcf96fd681e7d: Support "%R" (Database + Table Ref) in qsprintf(...)
Branches
Unknown
Tags
Unknown
Build Status
Buildable 21122
Build 28716: Run Core Tests