@rbxts/jsnatives
timeEnd
Stops a previously started timer and prints the elapsed time to the console.
Signature
function timeEnd(label?: string): void
Description
The console.timeEnd
method stops a timer that was previously started with console.time()
and logs the elapsed time to the console. It uses the same label to identify which timer to stop.
Parameters
label
(optional): A string identifying the timer to stop. If omitted, the default timer is stopped.
Return value
- None (void). However, it logs the elapsed time to the console.
Examples
Basic usage
// Start a timerconsole.time();
// Perform some operationfor (let i = 0; i < 1000000; i++) { // Simulate work}
// Stop the timer and log elapsed timeconsole.timeEnd();// Outputs: default: 15.123ms (time will vary)
Using a custom label
// Start a timer with a custom labelconsole.time("dataProcessing");
// Perform some data processingconst result = processLargeDataSet();
// Stop the timer and log elapsed timeconsole.timeEnd("dataProcessing");// Outputs: dataProcessing: 123.456ms (time will vary)
Multiple timers
// Start multiple timersconsole.time("timer1");console.time("timer2");
// First operationfor (let i = 0; i < 500000; i++) { // Work for timer1}console.timeEnd("timer1");
// Second operationfor (let i = 0; i < 1000000; i++) { // Work for timer2}console.timeEnd("timer2");
// Outputs:// timer1: 25.123ms// timer2: 50.456ms