Socket
Socket
Sign inDemoInstall

timer-set

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.6 to 1.0.7

test/timer-set/Scenarios-2.xlsx

2

examples/col-group/col-group.js

@@ -62,3 +62,3 @@ /***************************************************************************************************

this.counter = readList(file, delim, col);
this.maxLen = Utils.maxLen (this.counter);
this.maxLen = Utils.maxLen(this.counter);
}

@@ -65,0 +65,0 @@ /***************************************************************************************************

@@ -37,4 +37,4 @@ /***************************************************************************************************

const ColGroup = require('./col-group');
const TimerSet = require('timer-set');
const [INPUT_FILE, DELIM, COL] =
const TimerSet = require('timer-set'); // for non-npm package usage, use '../../lib/timer-set' instead
const [INPUT_FILE, DELIM, COL] =
['./examples/col-group/fantasy_premier_league_player_stats.csv', ',', 6];

@@ -41,0 +41,0 @@

@@ -52,13 +52,19 @@ /***************************************************************************************************

}
/***************************************************************************************************
valWidths: Handle parameter defaulting, and validate width parameters, int() where necessary
Parameters: time width and decimal places, time ratio dp, calls width
***************************************************************************************************/
function valWidths(time_width, time_dp, time_ratio_dp, calls_width = 5) {
if (calls_width < 5)
throw new Error('Error, ' + 'calls_width must be > 4, actual: ' + calls_width);
throw new Error('Error, calls_width must be > 4, actual: ' + calls_width);
else if (time_width < 0 || time_dp < 0 || time_ratio_dp < 0)
throw new Error('Error, ' + 'time_width, time_dp, time_ratio_dp must be > 0, actual: ' +
time_width + ', ' + time_dp + ', ' + time_ratio_dp);
throw new Error('Error, time_width, time_dp, time_ratio_dp must be > 0, actual: ' +
time_width + ', ' + time_dp + ', ' + time_ratio_dp);
else if (+time_width + +time_dp < 7)
throw new Error('Error, ' + 'time_width + time_dp must be > 6, actual: ' + time_width + ' + ' +
time_dp);
throw new Error('Error, time_width + time_dp must be > 6, actual: ' + time_width + ' + ' +
time_dp);
else if (+time_width + +time_ratio_dp < 8)
throw new Error('Error, ' + 'time_width + time_ratio_dp must be > 7, actual: ' + time_width +
throw new Error('Error, time_width + time_ratio_dp must be > 7, actual: ' + time_width +
' + ' + time_ratio_dp);

@@ -73,15 +79,15 @@ }

return Utils.rJust((t / TIME_FACTOR).toFixed (dp), time_width + dp);
};
}
function formTimeTrim(t, dp, time_width) { // time, decimal places to print, time width
return formTime(t, dp, time_width).trim();
};
}
function formName(name, maxName) { // timer name, maximum timer name length
return Utils.lJust(name, maxName);
};
}
function formCalls(calls, calls_width) { // timer name, maximum timer name length
return Utils.rJust(calls.toString(), calls_width);
};
}
/***************************************************************************************************
timerLine: Writes a formatted timing line
timerLine: Returns a formatted timing line
Parameters: timer name, maximum timer name length, elapsed, cpu times, number of calls to timer,

@@ -93,11 +99,11 @@ time fields width, decimal places for times and time ratios, calls field width

calls_width) {
return Utils.prListAsLine([formName(timer, maxName),
formTime(ela, time_dp, time_width),
formTime(usr, time_dp, time_width),
formTime(sys, time_dp, time_width),
formCalls(calls, calls_width),
formTime(ela/calls, time_ratio_dp, time_width),
formTime(usr/calls, time_ratio_dp, time_width),
formTime(sys/calls, time_ratio_dp, time_width)]);
};
return [formName( timer, maxName),
formTime( ela, time_dp, time_width),
formTime( usr, time_dp, time_width),
formTime( sys, time_dp, time_width),
formCalls(calls, calls_width),
formTime( ela/calls, time_ratio_dp, time_width),
formTime( usr/calls, time_ratio_dp, time_width),
formTime( sys/calls, time_ratio_dp, time_width)].join (' ');
}
class TimerSet {

@@ -110,3 +116,3 @@

*************************************************************************************************/
constructor(timerSetName, p_now = Date.now, p_cpus = os.cpus) { // timer set name, timinf functions
constructor(timerSetName, p_now = Date.now, p_cpus = os.cpus) {// timer set name, timing functions
this.now = p_now;

@@ -121,3 +127,2 @@ this.cpus = p_cpus;

}
/*************************************************************************************************

@@ -133,4 +138,3 @@

this.timPri = getTimes(this.now, this.cpus);
};
}
/*************************************************************************************************

@@ -154,5 +158,4 @@

});
this.timPri = curTim;//this.initTime();
};
this.timPri = curTim;
}
/*************************************************************************************************

@@ -166,7 +169,7 @@

const tim = getTimes(this.now, this.cpus);
const totTim = {ela : tim.ela - this.timBeg.ela, usr : tim.usr - this.timBeg.usr,
sys : tim.sys - this.timBeg.sys};
const totTim = {ela: tim.ela - this.timBeg.ela, usr: tim.usr - this.timBeg.usr,
sys: tim.sys - this.timBeg.sys};
const sumTim = Array.from(this.timerHash.values()).reduce(function(t, s) {
return {ela : t.ela + s.ela, usr : t.usr + s.usr, sys : t.sys + s.sys,
calls : t.calls + s.calls}; });
return {ela: t.ela + s.ela, usr: t.usr + s.usr, sys: t.sys + s.sys,
calls: t.calls + s.calls}; });

@@ -211,3 +214,3 @@ this.results = Array.from(this.timerHash.entries()).map(

return fmtArr;
};
}
/*************************************************************************************************

@@ -219,3 +222,3 @@

static getSelfTimer() {
const timerTimer = new TimerSet ('timer');
const timerTimer = new TimerSet('timer');
let [t, i] = [0, 0];

@@ -238,3 +241,3 @@ while (t < SELF_TIME) {

valWidths(time_width, time_dp, time_ratio_dp);
const t = this.getSelfTimer();
const t = TimerSet.getSelfTimer();
return '[Timer timed (per call in ms): Elapsed: ' + formTimeTrim(TIME_FACTOR*t.ela,

@@ -241,0 +244,0 @@ time_ratio_dp, time_width) + ', USR: ' + formTimeTrim(TIME_FACTOR*t.usr, time_ratio_dp,

@@ -48,13 +48,6 @@ "use strict";

prListAsLine: Prints an array of strings as one line, separating fields by a 2-space delimiter
***************************************************************************************************/
prListAsLine : (items, indentLev = 0) => items.join (' '), // array of strings to print as line
/***************************************************************************************************
rJust, lJust: Right/left-justify a string or number, using valJust to validate input
***************************************************************************************************/
valJust: (name, len) => {
valJust: (name, len) => { // string to print, width
const sname = String(name);

@@ -64,13 +57,13 @@ if (len < sname.length) throw new Error("*Just passed invalid parameters: " + sname + ", " + len);

},
rJust: (name, len) => {
rJust: (name, len) => { // string to print, width
const vals = self.valJust(name, len);
return vals[1] + vals[0];
}, // string to print, width
lJust: (name, len) => {
},
lJust: (name, len) => { // string to print, width
const vals = self.valJust(name, len);
return vals[0] + vals[1];
}, // string to print, width
},
/***************************************************************************************************
colHeaders: Prints a set of column headers, input as arrays of values and length/justification's
colHeaders: Returns a set of column headers, input as arrays of values and length/justification's

@@ -77,0 +70,0 @@ ***************************************************************************************************/

{
"name": "timer-set",
"version": "1.0.6",
"version": "1.0.7",
"description": "Code timing class",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/BrenPatF/timer-set_nodejs#readme",

@@ -36,3 +36,3 @@ /***************************************************************************************************

const Utils = require('../lib/utils');
const TimerSet = require('timer-set');
const TimerSet = require('timer-set'); // for non-npm package usage, use '../../lib/timer-set' instead
const fs = require('fs');

@@ -50,6 +50,12 @@ const ROOT = './test/';

["Self (unmocked)", "Self (unmocked, formatted)", "Results", "Exception"];
const testData = Trapit.getUTData(INPUT_JSON);
const [meta, callScenarios] = [testData.meta, testData.scenarios];
function purelyWrapUnit(callScenario) {
/**************************************************************************************************
purelyWrapUnit: Unit test wrapper function. This is called within a loop over input scenarios,
returning an object that includes the input object and has the actual program outputs
inserted
**************************************************************************************************/
function purelyWrapUnit(callScenario) {// json object for a single scenario, with inputs and
// expected outputs
const [mock_yn, timeWidth, dpTotals, dpPerCall, callsWidth] =

@@ -75,42 +81,28 @@ [...Utils.csvToLis(callScenario.inp[SCALARS][0]).map(v => v === '' ? undefined : v)];

[{[TIMER_SET_1]: [], [TIMER_SET_2]: []}, {[TIMER_SET_1]: [], [TIMER_SET_2]: []}, [], [], [], []];
for (const i in events) {
const eLis = Utils.csvToLis(events[i]);
const [setNm, timerNm, event, sleepTime, ela, usr, sys] = [...eLis];
for (const eventCsv of events) {
const eLis = Utils.csvToLis(eventCsv);
const [setNm, timerNm, event, sleepTime] = [...eLis];
if (mock_yn != 'Y') Utils.sleep(sleepTime);
switch(event) {
case CON:
if (mock_yn === 'Y') {
timerSet[setNm] = new TimerSet(setNm, now, cpus);
} else {
timerSet[setNm] = new TimerSet(setNm);
}
break;
case INC:
timerSet[setNm].incrementTime(timerNm);
break;
case INI:
timerSet[setNm].initTime();
break;
case GET:
outArr[setNm] = timerSet[setNm].getTimers().map(t => Object.values(t).join(DELIM));
break;
case GETF:
try {
outArrF[setNm] = timerSet[setNm].formatTimers(timeWidth, dpTotals, dpPerCall, callsWidth);
} catch(e) {
exceptions[0] = e.message;
exceptions[1] = e.stack;
}
break;
case SELF:
selfTimer = [Object.values(TimerSet.getSelfTimer()).join(DELIM)];
break;
case SELFF:
selfTimerF = [TimerSet.formatSelfTimer()];
break;
case RES:
results = [timerSet[setNm].formatResults()];
break;
default:
throw `Error event ${event} not known`;
if (event == CON) {
timerSet[setNm] = (mock_yn === 'Y') ? new TimerSet(setNm, now, cpus) : new TimerSet(setNm);
} else if (event == INC) {
timerSet[setNm].incrementTime(timerNm);
} else if (event == INI) {
timerSet[setNm].initTime();
} else if (event == GET) {
outArr[setNm] = timerSet[setNm].getTimers().map(t => Object.values(t).join(DELIM));
} else if (event == GETF) {
try {
outArrF[setNm] = timerSet[setNm].formatTimers(timeWidth, dpTotals, dpPerCall, callsWidth);
} catch(e) {
exceptions = [e.message, e.stack]
}
} else if (event == SELF) {
selfTimer = [Object.values(TimerSet.getSelfTimer()).join(DELIM)];
} else if (event == SELFF) {
selfTimerF = [TimerSet.formatSelfTimer()];
} else if (event == RES) {
results = [timerSet[setNm].formatResults()];
} else {
throw `Error event ${event} not known`;
}

@@ -156,3 +148,14 @@ }

}
/***************************************************************************************************
Testing main section:
Read test input data from json file as object with meta and (call) scenarios objects
Loop over scenarios passing in the calling scenario to the wrapper function, and assigning
return value to the (augmented) scenarios object element for the current scenario
Call trapit function to write test results, passing in the full augmented scenarios object with
the metadata
***************************************************************************************************/
const testData = Trapit.getUTData(INPUT_JSON);
const [meta, callScenarios] = [testData.meta, testData.scenarios];
let scenarios = [];

@@ -159,0 +162,0 @@ for (const s in callScenarios) {

@@ -112,3 +112,3 @@ Unit Test Report: timer-set

1 LIKE /Timer[^]*Timer 1[^]*\[Timer timed[^]*\]/:
Timer set: Set 1, constructed at Wed Nov 07 2018 07:05:27, written at Wed Nov 07 2018 07:05:27
Timer set: Set 1, constructed at Fri Dec 21 2018 10:37:37, written at Fri Dec 21 2018 10:37:37
==============================================================================================

@@ -123,3 +123,3 @@ Timer Elapsed USR SYS Calls Ela/Call USR/Call SYS/Call

------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
[Timer timed (per call in ms): Elapsed: 0.21782, USR: 0.00000, SYS: 0.01980]
[Timer timed (per call in ms): Elapsed: 0.13000, USR: 0.00000, SYS: 0.02000]

@@ -180,8 +180,8 @@ } 0 failed of 1: SUCCESS

# Timer Name Elapsed Time User CPU Time System CPU Time #Calls
- ---------- -------------------- -------------------- ------------------- ------
1 Timer 1 IN [2000,3000]: 2046 IN [0,1000]: 277.375 IN [0,1000]: 7.75 2
2 Timer 2 IN [1000,3000]: 1024 IN [0,1000]: 131 IN [0,1000]: 2 1
3 (Other) IN [4000,5000]: 4092 IN [0,1000]: 523.5 IN [0,1000]: 5.875 1
4 Total IN [6000,8000]: 7162 IN [0,2000]: 931.875 IN [0,2000]: 15.625 4
# Timer Name Elapsed Time User CPU Time System CPU Time #Calls
- ---------- -------------------- -------------------- -------------------- ------
1 Timer 1 IN [2000,3000]: 2046 IN [0,1000]: 265.625 IN [0,1000]: 50.875 2
2 Timer 2 IN [1000,3000]: 1023 IN [0,1000]: 132.75 IN [0,1000]: 15.5 1
3 (Other) IN [4000,5000]: 4092 IN [0,1000]: 527.25 IN [0,1000]: 68.5 1
4 Total IN [6000,8000]: 7161 IN [0,2000]: 925.625 IN [0,2000]: 134.875 4

@@ -198,7 +198,7 @@ } 0 failed of 4: SUCCESS

2 ------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
3 LIKE /Timer 1.*/: Timer 1 2.05 0.28 0.01 2 1.02300 0.13869 0.00387
4 LIKE /Timer 2.*/: Timer 2 1.02 0.13 0.00 1 1.02400 0.13100 0.00200
5 LIKE /\(Other\).*/: (Other) 4.09 0.52 0.01 1 4.09200 0.52350 0.00588
3 LIKE /Timer 1.*/: Timer 1 2.05 0.27 0.05 2 1.02300 0.13281 0.02544
4 LIKE /Timer 2.*/: Timer 2 1.02 0.13 0.02 1 1.02300 0.13275 0.01550
5 LIKE /\(Other\).*/: (Other) 4.09 0.53 0.07 1 4.09200 0.52725 0.06850
6 ------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
7 LIKE /Total.*/: Total 7.16 0.93 0.02 4 1.79050 0.23297 0.00391
7 LIKE /Total.*/: Total 7.16 0.93 0.13 4 1.79025 0.23141 0.03372
8 ------- ---------- ---------- ---------- ---------- ------------- ------------- -------------

@@ -212,7 +212,7 @@

# Timer Name Elapsed Time User CPU Time System CPU Time #Calls
- ---------- -------------------- -------------------- ------------------ ------
1 Timer 1 IN [4000,5000]: 4092 IN [0,1000]: 527.25 IN [0,1000]: 4 2
2 (Other) IN [2000,3000]: 2088 IN [0,1000]: 265.625 IN [0,1000]: 5.875 1
3 Total IN [6000,7000]: 6180 IN [0,2000]: 792.875 IN [0,2000]: 9.875 3
# Timer Name Elapsed Time User CPU Time System CPU Time #Calls
- ---------- -------------------- ------------------- ------------------- ------
1 Timer 1 IN [4000,5000]: 4092 IN [0,1000]: 527.25 IN [0,1000]: 72.25 2
2 (Other) IN [2000,3000]: 2084 IN [0,1000]: 267.5 IN [0,1000]: 45 1
3 Total IN [6000,7000]: 6176 IN [0,2000]: 794.75 IN [0,2000]: 117.25 3

@@ -228,5 +228,5 @@ } 0 failed of 3: SUCCESS

# Elapsed Time User CPU Time System CPU Time
- ------------------------------ -------------- ---------------
1 IN [0,0.5]: 0.1188118811881188 IN [0,0.05]: 0 IN [0,0.05]: 0
# Elapsed Time User CPU Time System CPU Time
- ---------------- -------------- --------------------
1 IN [0,0.5]: 0.12 IN [0,0.05]: 0 IN [0,0.05]: 0.01875

@@ -241,3 +241,3 @@ } 0 failed of 1: SUCCESS

- ------------------------------------------------------------------------------------------------------------------------------------
1 LIKE /\[Timer timed \(per call in ms\): Elapsed: .*\]/: [Timer timed (per call in ms): Elapsed: 0.15842, USR: 0.01856, SYS: 0.01980]
1 LIKE /\[Timer timed \(per call in ms\): Elapsed: .*\]/: [Timer timed (per call in ms): Elapsed: 0.13000, USR: 0.00000, SYS: 0.00000]

@@ -253,13 +253,13 @@ } 0 failed of 1: SUCCESS

1 LIKE /Timer[^]*Timer 1[^]*\[Timer timed[^]*\]/:
Timer set: Set 1, constructed at Wed Nov 07 2018 07:05:27, written at Wed Nov 07 2018 07:05:34
Timer set: Set 1, constructed at Fri Dec 21 2018 10:37:37, written at Fri Dec 21 2018 10:37:45
==============================================================================================
Timer Elapsed USR SYS Calls Ela/Call USR/Call SYS/Call
------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
Timer 1 2.05 0.28 0.01 2 1.02300 0.13869 0.00387
Timer 2 1.02 0.13 0.00 1 1.02400 0.13100 0.00200
(Other) 4.09 0.52 0.01 1 4.09200 0.52350 0.00588
Timer 1 2.05 0.27 0.05 2 1.02300 0.13281 0.02544
Timer 2 1.02 0.13 0.02 1 1.02300 0.13275 0.01550
(Other) 4.09 0.53 0.07 1 4.09200 0.52725 0.06850
------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
Total 7.16 0.93 0.02 4 1.79050 0.23297 0.00391
Total 7.16 0.93 0.13 4 1.79025 0.23141 0.03372
------- ---------- ---------- ---------- ---------- ------------- ------------- -------------
[Timer timed (per call in ms): Elapsed: 0.12871, USR: 0.01856, SYS: 0.00000]
[Timer timed (per call in ms): Elapsed: 0.13000, USR: 0.00000, SYS: 0.02000]

@@ -614,16 +614,16 @@ } 0 failed of 1: SUCCESS

# 1 Message, 2 Stack
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 Error, time_width + time_dp must be > 6, actual: 4 + 1
# 1 Message, 2 Stack
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 Error, time_width + time_dp must be > 6, actual: 4 + 1
2 UNTESTED: Error: Error, time_width + time_dp must be > 6, actual: 4 + 1
at valWidths (C:\Users\Brend_000\OneDrive\Script\npm\node_modules\timer-set\lib\timer-set.js:59:11)
at TimerSet.formatTimers (C:\Users\Brend_000\OneDrive\Script\npm\node_modules\timer-set\lib\timer-set.js:182:5)
at purelyWrapUnit (C:\Users\Brend_000\OneDrive\Script\npm\timer-set\test\test-timer-set.js:96:44)
at Object.<anonymous> (C:\Users\Brend_000\OneDrive\Script\npm\timer-set\test\test-timer-set.js:157:20)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at valWidths (C:\Users\Brend\OneDrive\Script\npm\timer-set\lib\timer-set.js:65:11)
at TimerSet.formatTimers (C:\Users\Brend\OneDrive\Script\npm\timer-set\lib\timer-set.js:186:5)
at purelyWrapUnit (C:\Users\Brend\OneDrive\Script\npm\timer-set\test\test-timer-set.js:93:42)
at Object.<anonymous> (C:\Users\Brend\OneDrive\Script\npm\timer-set\test\test-timer-set.js:160:20)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)

@@ -630,0 +630,0 @@ } 0 failed of 2: SUCCESS

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc