Profiling - Time difference in ms#26
Open
fijiwebdesign wants to merge 5 commits into
Open
Conversation
Owner
|
Ooh, nice hack, though I think you can get rid of var interval = new Date();
interval.now = (new Date()).getTime();
interval.toString = function () {
return -this.now + (this.now = new Date().getTime())
}
log = console.log.bind(console, " +%sms ", interval);
log('A');
log('B');
log('C'); |
Author
|
Ideas on getting the tests to pass? maybe expose interval so it can be mocked? or use regex on the results? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the time difference in millisecs between each call while preserving the file and line numbers of the caller.
Should be a start to fixing #17 and #22
The tests won't pass since they test for static values and the profiling adds dynamic time differences. It seems PhantomJS also doesn't have string interpolation in the console.log and we need that to pass Date and coerce to string.
How it works is that Date.prototype.toString() is called when the Date instance coerced into a string. This allows us to return a different scalar value each time console.log interpolates %s for our Date instance by overriding toString() locally on the instance.
Overriding
instance.__proto__works in Node and the browser. It is supported by all major browsers and IE11+ but not a spec. It will be supported for legacy ES5 in ES6 specs. See: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/protoCurrently can't think of a way to avoid using proto.