Skip to content

Commit 4a52060

Browse files
committed
fix: use first log as spinner
1 parent b2c63b2 commit 4a52060

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/time.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const shuffle = (arr) => {
5252
*/
5353
const timeRepo = (algos, args, runs, id) => {
5454
if (runs < 1) throw new RangeError(`runs:${runs} must be > 0`)
55+
console.log('\nMeasuring running time...\n')
5556

5657
// Initialize data object
5758
const times = {}
@@ -67,11 +68,10 @@ const timeRepo = (algos, args, runs, id) => {
6768
}
6869
}
6970

70-
// Sort times
71-
const sortedTimes =
72-
Object
73-
.entries(times)
74-
.sort((a, b) => a[1] - b[1])
71+
// Sort times in ascending order
72+
const sortedTimes = Object
73+
.entries(times)
74+
.sort((a, b) => a[1] - b[1])
7575

7676
return { id, sortedTimes, args, runs }
7777
}
@@ -83,10 +83,12 @@ const timeRepo = (algos, args, runs, id) => {
8383
*/
8484
const parseResult = ({ id, sortedTimes, args, runs }) => {
8585
let parsedResult =
86-
`\nRunning time results\n${id}\nargs: ${args}\nruns: ${runs}\n\n`
86+
`${id}\nargument list: ${args}\nnumber of runs: ${runs}\n\n`
8787

88-
for (const idRes of sortedTimes) {
89-
parsedResult += `${idRes[0]}: ${idRes[1].toFixed(3)} ms\n`
88+
for (let idx = 0; idx < sortedTimes.length; idx++) {
89+
const left = `${idx + 1}: ${sortedTimes[idx][1].toFixed(3)} ms - `
90+
const right = `${sortedTimes[idx][0]}\n`
91+
parsedResult += `${left}${right}`
9092
}
9193

9294
return parsedResult

0 commit comments

Comments
 (0)