-
Notifications
You must be signed in to change notification settings - Fork 939
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
Add timed sections #485
base: master
Are you sure you want to change the base?
Add timed sections #485
Conversation
An alternative/additional syntax could be: debug.time('some procedure', () => {
// ... some lengthy operation
}); which would be sugar for var sec = debug.begin('some procedure');
try {
fn();
} finally {
sec.end();
} Could even support promises if they're available. Thoughts? EDIT: went ahead and added them - feel free to revert the commit. Usage: const result = debug.time('some critical function', () => {
// do work
return 1234;
});
console.log(result); //-> 1234
const result2 = await debug.time('some critical async function', async () => {
// do work
return 54321;
});
console.log(result); //-> 54321 |
Latest commits do the following: const sec = debug.begin('section');
sec.mark(); // OK
sec.mark(); // OK
sec.end(); // OK
sec.mark(); // no output
sec.end(); // no output May be reasonable to throw instead of swallow the output? Let me know. cc @TooTallNate debug.time('some function', sec => {
// work...
sec.mark('some mark');
// more work...
sec.end('some result');
}); |
1 similar comment
@Qix- Very interesting! I did something similar (though a lot more basic) using a custom formatter. That said, my initial question is if this is something that could live as a separate module like my |
The mechanics rely heavily on the formatter and the indirection of the main debug function to be efficient. I don't know if you could do that without a complete fork. |
2 similar comments
exports.formatters = {}; | ||
exports.formatters = { | ||
s: String, | ||
i: function (v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt(v, 10)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const o = { valueOf: () => 1234 };
parseInt(o, 10); //-> NaN
Number(o); //-> 1234
Let's get this merged @Qix-. Needs Readme docs and there appears to be a bug where the marked sections fall back to a regular debug() call when stdout is not a TTY (server logs, etc.) that needs to be fixed first as well. |
This is a really nice feature. @Qix- |
Any plans to get this in @Qix- ? |
This adds timed sections, similar to
console.time()
andconsole.timeEnd()
.I understand completely if this isn't something you guys want added. However, it should be a non-breaking change.
If it is something you're interested in, I'll add docs to the readme :)
This works both in the browser and in Node.
Usage:
As you'd expect,
.mark()
is entirely optional, and the arguments to.mark()
and.end()
are optional as well.Arguments passed to
.mark()
and.end()
are separated from the.begin()
text with::
, and all formatting parameters are preserved as you'd expect - even in the browser:The separation with
::
is a trivial change, so if you don't like the way it looks or have a better idea on how to introduce the mark/end text to the existing arguments provided by.begin()
, let me know and I can whip it up.