php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
hrtime.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Niklas Keller <kelunik@php.net> |
14 | Author: Anatol Belski <ab@php.net> |
15 +----------------------------------------------------------------------+
16 */
17
18#include "php.h"
19#include "zend_hrtime.h"
20
21#ifdef ZEND_ENABLE_ZVAL_LONG64
22#define PHP_RETURN_HRTIME(t) RETURN_LONG((zend_long)t)
23#else
24#ifdef _WIN32
25# define HRTIME_U64A(i, s, len) _ui64toa_s(i, s, len, 10)
26#else
27# define HRTIME_U64A(i, s, len) \
28 do { \
29 int st = snprintf(s, len, "%llu", i); \
30 s[st] = '\0'; \
31 } while (0)
32#endif
33#define PHP_RETURN_HRTIME(t) do { \
34 char _a[ZEND_LTOA_BUF_LEN]; \
35 double _d; \
36 HRTIME_U64A(t, _a, ZEND_LTOA_BUF_LEN); \
37 _d = zend_strtod(_a, NULL); \
38 RETURN_DOUBLE(_d); \
39 } while (0)
40#endif
41
42/* {{{ Returns an array of integers in form [seconds, nanoseconds] counted
43 from an arbitrary point in time. If an optional boolean argument is
44 passed, returns an integer on 64-bit platforms or float on 32-bit
45 containing the current high-resolution time in nanoseconds. The
46 delivered timestamp is monotonic and cannot be adjusted. */
48{
49#if ZEND_HRTIME_AVAILABLE
50 bool get_as_num = 0;
51 zend_hrtime_t t = zend_hrtime();
52
55 Z_PARAM_BOOL(get_as_num)
57
58 if (UNEXPECTED(get_as_num)) {
60 } else {
65 }
66#else
68#endif
69}
70/* }}} */
hrtime(bool $as_number=false)
#define PHP_RETURN_HRTIME(t)
Definition hrtime.c:33
#define PHP_FUNCTION
Definition php.h:364
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
Definition zend_API.c:2132
#define ZEND_PARSE_PARAMETERS_END()
Definition zend_API.h:1641
#define RETURN_FALSE
Definition zend_API.h:1058
#define array_init_size(arg, size)
Definition zend_API.h:538
#define Z_PARAM_OPTIONAL
Definition zend_API.h:1667
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define Z_PARAM_BOOL(dest)
Definition zend_API.h:1726
ZEND_API void ZEND_FASTCALL zend_hash_real_init_packed(HashTable *ht)
Definition zend_hash.c:330
#define ZEND_NANO_IN_SEC
Definition zend_hrtime.h:73
uint64_t zend_hrtime_t
Definition zend_hrtime.h:75
int32_t zend_long
Definition zend_long.h:42
#define UNEXPECTED(condition)
#define Z_ARRVAL_P(zval_p)
Definition zend_types.h:987
zval * return_value