markdown 使用控制台日志记录运行函数所需的时间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 使用控制台日志记录运行函数所需的时间相关的知识,希望对你有一定的参考价值。

## To set up the time log function

```
const timeIt = (label, fn) => {
  console.time(label);
  fn();
  console.timeEnd(label);
}
```

## Example to use it

```
const arrayOfRandoms = randomCeil => length => Array.from({length: length}, (v, i) => Math.floor(Math.random() * randomCeil));

const arrOfThousand = arrayOfRandoms(100)(1000);

// use time log
timeIt('thousand - map', () => {
  const resultFrom1000 = arrOfThousand
    .map(val => val * 3);
});
```

以上是关于markdown 使用控制台日志记录运行函数所需的时间的主要内容,如果未能解决你的问题,请参考以下文章