timer-set
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -70,6 +70,6 @@ /*************************************************************************************************** | ||
***************************************************************************************************/ | ||
function formTime(t, dp, time_width) { // time, decimal places to print | ||
function formTime(t, dp, time_width) { // time, decimal places to print, time width | ||
return Utils.rJust((t / TIME_FACTOR).toFixed (dp), time_width + dp); | ||
}; | ||
function formTimeTrim(t, dp, time_width) { // time, decimal places to print | ||
function formTimeTrim(t, dp, time_width) { // time, decimal places to print, time width | ||
return formTime(t, dp, time_width).trim(); | ||
@@ -85,4 +85,5 @@ }; | ||
writeTimeLine: Writes a formatted timing line | ||
Parameters: timer name, maximum timer name length, elapsed, cpu times, number of calls to timer | ||
timerLine: Writes a formatted timing line | ||
Parameters: timer name, maximum timer name length, elapsed, cpu times, number of calls to timer, | ||
time fields width, decimal places for times and time ratios, calls field width | ||
@@ -108,3 +109,3 @@ ***************************************************************************************************/ | ||
*************************************************************************************************/ | ||
constructor(timerSetName, p_now = Date.now, p_cpus = os.cpus) { // timer set name | ||
constructor(timerSetName, p_now = Date.now, p_cpus = os.cpus) { // timer set name, timinf functions | ||
this.now = p_now; | ||
@@ -186,3 +187,3 @@ this.cpus = p_cpus; | ||
valWidths(time_width, time_dp, time_ratio_dp, calls_width); | ||
const timerArr = this.getTimers(); | ||
const timerArr = this.getTimers(time_width, time_dp, time_ratio_dp, calls_width); | ||
const maxName = Utils.maxLen(this.timerHash); | ||
@@ -193,5 +194,5 @@ const [lenTime, lenTimeRatio] = [+time_width + +time_dp, +time_width + +time_ratio_dp]; | ||
{name: 'Elapsed', len: lenTime}, | ||
{name: 'USR', len: lenTime}, | ||
{name: 'SYS', len: lenTime}, | ||
{name: 'Calls', len: calls_width}, | ||
{name: 'USR', len: lenTime}, | ||
{name: 'SYS', len: lenTime}, | ||
{name: 'Calls', len: calls_width}, | ||
{name: 'Ela/Call', len: lenTimeRatio}, | ||
@@ -201,8 +202,6 @@ {name: 'USR/Call', len: lenTimeRatio}, | ||
for (const i in timerArr) { | ||
const t = timerArr[i]; | ||
for (const [i, t] of timerArr.entries()) { | ||
fmtArr.push(timerLine(t.timer, maxName, t.ela, t.usr, t.sys, t.calls, +time_width, +time_dp, | ||
+time_ratio_dp, +calls_width)); | ||
if (i == timerArr.length - 2) {fmtArr.push(fmtArr[1])}; | ||
if (i == timerArr.length - 1) {fmtArr.push(fmtArr[1])}; | ||
if (i > timerArr.length - 3) {fmtArr.push(fmtArr[1])}; | ||
}; | ||
@@ -221,7 +220,7 @@ return fmtArr; | ||
timerTimer.incrementTime('x'); | ||
if((i++ + 1) % 100 == 0) t = timerTimer.timerHash.get('x').ela; | ||
if (++i % 100 == 0) t = timerTimer.timerHash.get('x').ela; | ||
}; | ||
const timerTimes = timerTimer.timerHash.get('x'); | ||
return {ela: timerTimes.ela/(i + 1), usr: timerTimes.usr/(i + 1), | ||
sys: timerTimes.sys/(i + 1)}; | ||
return {ela: timerTimes.ela/i, usr: timerTimes.usr/i, | ||
sys: timerTimes.sys/i}; | ||
} | ||
@@ -253,3 +252,4 @@ /************************************************************************************************* | ||
", written at " + Date().substring(0,24)) + '\n' + | ||
(this.formatTimers()).reduce(function(s, l) {return s + '\n' + l}) + '\n' + | ||
(this.formatTimers(time_width, time_dp, time_ratio_dp,calls_width)).reduce( | ||
function(s, l) {return s + '\n' + l}) + '\n' + | ||
TimerSet.formatSelfTimer(time_width, time_dp, time_ratio_dp); | ||
@@ -256,0 +256,0 @@ } |
@@ -55,14 +55,17 @@ "use strict"; | ||
rJust, lJust: Right/left-justify a string or number | ||
rJust, lJust: Right/left-justify a string or number, using valJust to validate input | ||
***************************************************************************************************/ | ||
valJust: (name, len) => { | ||
const sname = String(name); | ||
if (len < sname.length) throw new Error("*Just passed invalid parameters: " + sname + ", " + len); | ||
return [sname, ' '.repeat(len - sname.length)]; | ||
}, | ||
rJust: (name, len) => { | ||
const sname = String(name); | ||
if (len < sname.length) throw new Error("rJust passed invalid parameters: " + sname + ", " + len); | ||
return ' '.repeat(len - sname.length) + sname | ||
const vals = self.valJust(name, len); | ||
return vals[1] + vals[0]; | ||
}, // string to print, width | ||
lJust: (name, len) => { | ||
const sname = String(name); | ||
if (len < sname.length) throw new Error("lJust passed invalid parameters: " + sname + ", " + len); | ||
return sname + ' '.repeat(len - sname.length) | ||
const vals = self.valJust(name, len); | ||
return vals[0] + vals[1]; | ||
}, // string to print, width | ||
@@ -75,6 +78,6 @@ /*************************************************************************************************** | ||
colHeaders: (items) => { // array of {name, length} objects, length < 0 -> left-justify | ||
let strings = items.map( (j) => { | ||
return j.len < 0 ? self.lJust(j.name, -j.len) : self.rJust(j.name, j.len)}); | ||
let strings = items.map( (s) => { | ||
return s.len < 0 ? self.lJust(s.name, -s.len) : self.rJust(s.name, s.len)}); | ||
let lines = [strings.join (' ')]; | ||
let unders = strings.map( (j) => {return '-'.repeat(j.length)}) | ||
let unders = strings.map( (s) => {return '-'.repeat(s.length)}) | ||
lines.push(unders.join (' ')); | ||
@@ -81,0 +84,0 @@ return lines; |
{ | ||
"name": "timer-set", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Code timing class", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/BrenPatF/timer-set_nodejs#readme", |
2463678
914