-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (31 loc) · 1.1 KB
/
Copy pathapp.js
File metadata and controls
35 lines (31 loc) · 1.1 KB
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
31
32
33
34
35
const express = require('express');
const app = express();
const port = 3000;
const {performance} = require('perf_hooks');
app.get('/index', (req, res) => {
const start = performance.now();
const response = "Hello";
const end = performance.now();
const executionTime = end - start;
if (executionTime > 100) {
console.warn(`Warning: Execution time for /index exceeded limit (${executionTime} ms)`);
}
res.send(response);
});
app.get('/moreload', (req, res) => {
const start = performance.now();
const numbers = Array.from({length: 1000}, () => Math.floor(Math.random() * 1000));
const sumOfNumbers = numbers.reduce((acc, cur) => acc + cur, 0);
const end = performance.now();
const executionTime = end - start;
if (executionTime > 500) {
console.warn(`Warning: Execution time for /moreload exceeded limit (${executionTime} ms)`);
}
res.send(sumOfNumbers.toString());
});
app.get('/', (req, res) => {
res.send('Welcome to the Node Express App');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});