Skip to content

Commit

Permalink
use doubles for startTime and endTime
Browse files Browse the repository at this point in the history
don’t lose precision by doing integer arithmetic
  • Loading branch information
jaredp committed Jul 29, 2015
1 parent ed5b7ce commit ac3424f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cpu_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace nodex {
profile->Set(NanNew<String>("head"), head);

#if (NODE_MODULE_VERSION > 0x000B)
Local<Value> start_time = NanNew<Number>(node->GetStartTime()/1000000);
Local<Value> end_time = NanNew<Number>(node->GetEndTime()/1000000);
Local<Value> start_time = NanNew<Number>((double)node->GetStartTime()/1000000.00);
Local<Value> end_time = NanNew<Number>((double)node->GetEndTime()/1000000.00);
Local<Array> samples = NanNew<Array>();

uint32_t count = node->GetSamplesCount();
Expand Down
11 changes: 11 additions & 0 deletions test/cpu_cprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ describe('CPU', function() {
expect(profile.samples.length > 0).to.equal(true);
});

it('should record startTime and endTime with subsecond precision', function(done) {
profiler.startProfiling('P');
var delayInMilliseconds = 150;
setTimeout(function() {
var profile = profiler.stopProfiling();
var elapsedTime = profile.endTime - profile.startTime;
expect(elapsedTime).to.be.at.least(delayInMilliseconds / 1000);
expect(elapsedTime).to.be.at.below(3 * delayInMilliseconds / 1000);
done();
}, delayInMilliseconds);
});
});

describe('Profile', function() {
Expand Down

0 comments on commit ac3424f

Please sign in to comment.