Page MenuHomePhabricator

Add a convenience function for computing elapsed microtime deltas
ClosedPublic

Authored by epriestley on Nov 8 2018, 2:13 PM.
Tags
None
Referenced Files
F19506754: D19796.id47274.diff
Fri, Jan 9, 4:53 PM
F19505336: D19796.id47274.diff
Fri, Jan 9, 11:06 AM
F19235359: D19796.diff
Sun, Dec 21, 6:41 PM
F19101169: D19796.diff
Dec 5 2025, 1:55 AM
F19082858: D19796.id47274.diff
Dec 2 2025, 12:26 PM
F19078038: D19796.diff
Dec 1 2025, 5:01 PM
F18984962: D19796.id47270.diff
Nov 17 2025, 12:49 PM
F18960504: D19796.diff
Nov 13 2025, 11:58 AM
Subscribers
None

Details

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

Diff Detail

Repository
rPHU libphutil
Branch
micros1
Lint
Lint Errors
SeverityLocationCodeMessage
Errorsrc/utils/utils.php:1317XHP45PHP Compatibility
Errorsrc/utils/utils.php:1317XHP45PHP Compatibility
Unit
Tests Passed
Build Status
Buildable 21118
Build 28709: Run Core Tests
Build 28708: arc lint + arc unit