Метод node.js console.timeLog()

Опубликовано: 4 Января, 2023

Метод console.timeLog() — это встроенная в Nodejs функция, которая используется для отображения времени каждого выполнения. Эта функция доказала свою эффективность при использовании в цикле.

Синтаксис:

console.log([label][, ...data])

Параметры: эта функция принимает два или более параметра.

Возвращаемое значение: этот метод отображает время выполнения.

Примеры ниже иллюстрируют метод console.timeLog() в Node.js:

Пример 1:




// Node.js program to demonstrate the   
// console.timeLog() method
  
// Time started
console.time("executionTime");
for (let i = 0; i < 10; i++) {
  
    // Printing execution time for each
    console.timeLog("executionTime");
}

Выход:

Пример 2:




// Node.js program to demonstrate the   
// console.timeLog() method
  
// Time started
console.time("totalExecutionTime");
  
// Time started
console.time("executionTime");
  
for (let i = 0; i < 10; i++) {
  
    // Printing execution time for each
    console.timeLog("executionTime");
}
  
// Printing total execution time
console.timeLog("totalExecutionTime");

Выход:

Ссылка: https://nodejs.org/api/console.html#console_console_timelog_label_data