Skip to content

Commit eb97770

Browse files
committed
⭐ init
1 parent 362ed2b commit eb97770

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

measurePerformance.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
export function measurePerformance(cb) {
3+
const start = performance.now();
4+
cb();
5+
const end = performance.now();
6+
return (end - start)/ 1000;
7+
}
8+
9+
const addUpTo = (n) => {
10+
return n * (n + 1) / 2;
11+
}
12+
13+
const addUpTo2 = (n) => {
14+
let total = 0;
15+
for (let i = 1; i <= n; i++) {
16+
total += i;
17+
}
18+
return total;
19+
}
20+
21+
22+
console.log(measurePerformance(() => addUpTo(10_000_000_000)));
23+
console.log(measurePerformance(() => addUpTo2(10_000_000_000)));

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "js-algorithms",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"description": "",
6+
"main": "measurePerformance.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC"
12+
}

0 commit comments

Comments
 (0)