1 Star 0 Fork 0

白一梓 / bench4slogger

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
fun.js 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
白一梓 提交于 2018-04-30 19:26 . add the test of 0.5.2
var Benchmark = require('benchmark');
// var util = require('util');
var suite = new Benchmark.Suite;
const NEW_LINE_SEPARATOR = require('os').EOL;
const consoleProvider = require('./v0.4.1/lib/providers/console_provider')(null,{flushInterval:1000});
const args = ['this is version x'];
/**
*
*
* @param {Date} date
*/
function dateFormat(date) {
return date.getFullYear()+'-' + (date.getMonth() + 1) + ' '+date.getDate() + ' '+date.getHours()+':'+date.getMinutes() + ':'+date.getSeconds();
}
function myFormat(params) {
var str = '';
if (!params) {
return str;
}
var element;
for (var i=0,len=params.length;i<len;i++) {
element = params[i];
if (element instanceof Error) {
str += element.stack + '\n';
} else if (typeof(element) === 'object') {
str += ' '+ JSON.stringify(element);
} else {
str += element;
}
}
return str;
}
// var str = '';
// process.stdout._handle.setBlocking(false);
suite
.add('loop',function() {
var perfix = '\x1b[32m';
perfix += dateFormat(new Date());
perfix+= '['+'debug'+']';
var len = args.length;
const params = new Array(len+2);
params[0] = perfix;
for (var i=1;i<=len;i++) {
params[i] = args[i-1];
}
params[len+1] = '\x1b[0m';
// str += util.format.apply(null,params) + NEW_LINE_SEPARATOR;
str += myFormat(params) + NEW_LINE_SEPARATOR;
//console.info.apply(console,params);
})
.add('console provider',function() {
consoleProvider.print(args,'debug');
})
// .add('async',function() {
// alogger = logger41.init({flushInterval:500});
// alogger.debug('this is version as');
// })
.on('cycle', function(event) {// add listeners
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({async:true});
1
https://gitee.com/yunnysunny/bench4slogger.git
git@gitee.com:yunnysunny/bench4slogger.git
yunnysunny
bench4slogger
bench4slogger
master

搜索帮助