perf_hooks: implement performance.now() with fast API calls · nodejs/node@a7d8f6b · GitHub
Skip to content

Commit a7d8f6b

Browse files
joyeecheungUlisesGascon
authored andcommitted
perf_hooks: implement performance.now() with fast API calls
PR-URL: #50492 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent be54a22 commit a7d8f6b

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

benchmark/perf_hooks/now.js

Lines changed: 23 additions & 0 deletions

lib/internal/perf/utils.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN,
66
},
77
milestones,
8+
now,
89
} = internalBinding('performance');
910

1011
function getTimeOrigin() {
@@ -13,12 +14,6 @@ function getTimeOrigin() {
1314
return milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN] / 1e6;
1415
}
1516

16-
// Returns the time relative to the process start time in milliseconds.
17-
function now() {
18-
const hr = process.hrtime();
19-
return (hr[0] * 1000 + hr[1] / 1e6) - getTimeOrigin();
20-
}
21-
2217
// Returns the milestone relative to the process start time in milliseconds.
2318
function getMilestoneTimestamp(milestoneIdx) {
2419
const ns = milestones[milestoneIdx];

src/node_external_reference.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ using CFunctionCallbackWithOneByteString =
1515
using CFunctionCallback = void (*)(v8::Local<v8::Value> receiver);
1616
using CFunctionCallbackReturnDouble =
1717
double (*)(v8::Local<v8::Object> receiver);
18+
using CFunctionCallbackValueReturnDouble =
19+
double (*)(v8::Local<v8::Value> receiver);
1820
using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> receiver,
1921
int64_t);
2022
using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> receiver,
@@ -38,6 +40,7 @@ class ExternalReferenceRegistry {
3840
V(CFunctionCallback) \
3941
V(CFunctionCallbackWithOneByteString) \
4042
V(CFunctionCallbackReturnDouble) \
43+
V(CFunctionCallbackValueReturnDouble) \
4144
V(CFunctionCallbackWithInt64) \
4245
V(CFunctionCallbackWithBool) \
4346
V(CFunctionCallbackWithString) \

src/node_perf.cc

Lines changed: 21 additions & 0 deletions

0 commit comments

Comments
 (0)