99
1010// Medium function - string manipulation
1111const parseAndFormat = ( ) => {
12- const data = Array . from ( { length : 100000 } , ( _ , i ) => {
12+ const data = Array . from ( { length : 100_000 } , ( _ , i ) => {
1313 const raw = `${ i } |item-${ i } |${ Math . random ( ) * 100 } ` ;
1414 const parts = raw . split ( '|' ) ;
1515 return {
@@ -23,7 +23,7 @@ const parseAndFormat = () => {
2323
2424// Warm function - moderate CPU time
2525const processStrings = ( ) => {
26- const strings = Array . from ( { length : 500000 } , ( _ , i ) => `item-${ i } ` ) ;
26+ const strings = Array . from ( { length : 500_000 } , ( _ , i ) => `item-${ i } ` ) ;
2727 return strings
2828 . map ( ( s ) => s . toUpperCase ( ) )
2929 . filter ( ( s ) => s . includes ( '5' ) )
@@ -32,7 +32,7 @@ const processStrings = () => {
3232
3333// Medium-warm function - JSON serialization
3434const serializeData = ( ) => {
35- const data = Array . from ( { length : 50000 } , ( _ , i ) => ( {
35+ const data = Array . from ( { length : 50_000 } , ( _ , i ) => ( {
3636 id : i ,
3737 metadata : { created : Date . now ( ) , updated : Date . now ( ) } ,
3838 name : `Record ${ i } ` ,
@@ -48,13 +48,13 @@ const simpleCalculation = () => {
4848
4949// Hot function - lots of CPU time
5050const sortLargeArray = ( ) => {
51- const arr = Array . from ( { length : 1000000 } , ( ) => Math . random ( ) ) ;
51+ const arr = Array . from ( { length : 1_000_000 } , ( ) => Math . random ( ) ) ;
5252 return arr . sort ( ( a , b ) => a - b ) ;
5353} ;
5454
5555// Warm function - object manipulation
5656const transformData = ( ) => {
57- const data = Array . from ( { length : 200000 } , ( _ , i ) => ( {
57+ const data = Array . from ( { length : 200_000 } , ( _ , i ) => ( {
5858 id : i ,
5959 name : `Item ${ i } ` ,
6060 value : Math . random ( ) * 100 ,
@@ -72,7 +72,7 @@ const transformData = () => {
7272// Another hot function - regex processing
7373const validateEmails = ( ) => {
7474 const emails = Array . from (
75- { length : 100000 } ,
75+ { length : 100_000 } ,
7676 ( _ , i ) => `user${ i } @example.com` ,
7777 ) ;
7878 const regex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
@@ -111,7 +111,7 @@ validateEmails();
111111transformData ( ) ;
112112
113113console . log ( 'Simple calculations (cold path)...' ) ;
114- for ( let i = 0 ; i < 10000 ; i ++ ) {
114+ for ( let i = 0 ; i < 10_000 ; i ++ ) {
115115 simpleCalculation ( ) ;
116116}
117117
0 commit comments