markdown 的NodeJS-的console.log时间线,function.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 的NodeJS-的console.log时间线,function.js相关的知识,希望对你有一定的参考价值。

function Timeline(timelineLabel){
	this.times = [];
	this.maxChars = 0;
	this.label = timelineLabel;
	this.add = function(label){
		let times = this.times;
		times.push({ label, hrtime: process.hrtime(), elapsed: times.length === 0 ? [0, 0] : process.hrtime(times[times.length - 1].hrtime) });
		if(this.maxChars < label.length) this.maxChars = label.length;
		return this;
	};
	this.log = function(){
		console.log("\n\n  [ "+ this.label +" ]\n\n" + this.times.map(time => "  " + time.label + (" ".repeat((this.maxChars - time.label.length) + 2)) + (time.elapsed[1] / 1000000) + "ms").join("\n"), "\n");
		return this;
	};
}
# Simple node.js interim logging function
###### (uses `process.hrtime`)

```js

// Create the timeline
const timeline = new Timeline("timeline label here");

// add to the timeline
timeline.add("time label here");

// log the timeline
timeline.log();

```

The returned time is determined by the previous timeline item. For example if the time between item 1 & item 2 was 100ms, item 2 will be 100ms.

Example:

![Request Test](https://cdn.jeremyjaydan.io/cdn/mdi/request-test.png)

以上是关于markdown 的NodeJS-的console.log时间线,function.js的主要内容,如果未能解决你的问题,请参考以下文章

NodeJS 中 BSON 对象的 console.log

NodeJS 中 BSON 对象的 console.log

nodejs,CSDN转markdown

markdown Ubuntu安装NodeJs

markdown NodeJS和NPM

markdown 干净安装NodeJS