Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: improve performance of process.hrtime() #4484

Merged
merged 1 commit into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2138,18 +2138,8 @@ void Kill(const FunctionCallbackInfo<Value>& args) {
// and nanoseconds, to avoid any integer overflow possibility.
// Pass in an Array from a previous hrtime() call to instead get a time diff.
void Hrtime(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

uint64_t t = uv_hrtime();

if (!args[1]->IsUndefined()) {
if (!args[1]->IsArray()) {
return env->ThrowTypeError(
"process.hrtime() only accepts an Array tuple");
}
args.GetReturnValue().Set(true);
}

Local<ArrayBuffer> ab = args[0].As<Uint32Array>()->Buffer();
uint32_t* fields = static_cast<uint32_t*>(ab->GetContents().Data());

Expand Down
24 changes: 16 additions & 8 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,23 @@
}

process.hrtime = function hrtime(ar) {
const ret = [0, 0];
if (_hrtime(hrValues, ar)) {
ret[0] = (hrValues[0] * 0x100000000 + hrValues[1]) - ar[0];
ret[1] = hrValues[2] - ar[1];
} else {
ret[0] = hrValues[0] * 0x100000000 + hrValues[1];
ret[1] = hrValues[2];
_hrtime(hrValues);

if (typeof ar !== 'undefined') {
if (Array.isArray(ar)) {
return [
(hrValues[0] * 0x100000000 + hrValues[1]) - ar[0],
hrValues[2] - ar[1]
];
}

throw new TypeError('process.hrtime() only accepts an Array tuple');
}
return ret;

return [
hrValues[0] * 0x100000000 + hrValues[1],
hrValues[2]
];
};
};

Expand Down