-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 904 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const readline = require('readline');
const { stdin: input, stdout: output } = require('process');
const { catchPokemons } = require('./pokemon-ash')
const rl = readline.createInterface({ input, output, terminal: false });
/**
* The listener function is called with a string containing the single line of received input
*/
rl.on('line', (input) => {
/**
* if test memory, time performance
*/
if (process.env.TEST_PERFORMANCE) {
console.time('time_execute')
const result = catchPokemons(input);
console.timeEnd('time_execute')
console.log(`${result}`);
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`The apllication uses approximately ${Math.round(used * 100) / 100} MB of heap memory Used`);
} else {
const result = catchPokemons(input);
console.log(result);
}
rl.close();
});