File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ .idea /
Original file line number Diff line number Diff line change 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 ) ) ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments