Implement console.time, console.timeEnd, console.timeLog, console.count, and console.countReset#56385
Conversation
…nt, and console.countReset These methods were previously stubbed as no-ops. Developers using console.time() for profiling would silently get no output, which is confusing and makes debugging harder. The implementation follows the WHATWG Console spec: - console.time(label) starts a named timer - console.timeEnd(label) logs elapsed time and removes the timer - console.timeLog(label, ...data) logs elapsed time without stopping - console.count(label) logs how many times it has been called - console.countReset(label) resets a counter Uses nativePerformanceNow for high-resolution timing when available, with Date.now as a fallback.
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
a308979 to
a7399c2
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Implement five
consolemethods that were previously stubbed as no-ops in the React Native console polyfill:console.time(label)- Starts a named timer using high-resolutionnativePerformanceNow(withDate.nowfallback)console.timeEnd(label)- Logs the elapsed time and removes the timerconsole.timeLog(label, ...data)- Logs the elapsed time without stopping the timer, with optional extra dataconsole.count(label)- Logs how many times it has been called with the given labelconsole.countReset(label)- Resets the counter for the given labelAll five methods follow the WHATWG Console spec:
"default"when none is providedPreviously, developers using
console.time('myOperation')/console.timeEnd('myOperation')for profiling would silently get no output, making it look like the code was never reached. This was a common source of confusion.Changelog:
[GENERAL] [ADDED] - Implement console.time, console.timeEnd, console.timeLog, console.count, and console.countReset in the console polyfill
Test Plan
Added
consoleTimers-itest.jswith tests covering:timeLoglogging without stopping the timer