1+ console . log ( ' running text-buffer tests... \n' )
2+
13const assert = require ( 'assert' )
4+ const { performance} = require ( "perf_hooks" )
5+
26const { TextBuffer} = require ( '..' )
37
48const text = 'abc def ghi jkl\n' . repeat ( 1024 * 1024 )
@@ -8,14 +12,15 @@ const trialCount = 10
812
913function benchmarkSearch ( description , pattern , expectedPosition ) {
1014 let name = `Search for ${ description } - TextBuffer`
11- console . time ( name )
15+ const ti1 = performance . now ( )
1216 for ( let i = 0 ; i < trialCount ; i ++ ) {
13- assert . deepEqual ( buffer . searchSync ( pattern ) , expectedPosition )
17+ assert . deepEqual ( buffer . findSync ( pattern ) , expectedPosition )
1418 }
15- console . timeEnd ( name )
19+ const tf1 = performance . now ( )
20+ console . log ( `${ name } ${ ' ' . repeat ( 80 - name . length ) } ${ ( tf1 - ti1 ) . toFixed ( 3 ) } ms` )
1621
1722 name = `Search for ${ description } - lines array`
18- console . time ( name )
23+ const ti2 = performance . now ( )
1924 const regex = new RegExp ( pattern )
2025 for ( let i = 0 ; i < trialCount ; i ++ ) {
2126 for ( let row = 0 , rowCount = lines . length ; row < rowCount ; row ++ ) {
@@ -32,11 +37,14 @@ function benchmarkSearch(description, pattern, expectedPosition) {
3237 }
3338 }
3439 }
35- console . timeEnd ( name )
36- console . log ( )
40+ const tf2 = performance . now ( )
41+ console . log ( ` ${ name } ${ ' ' . repeat ( 80 - name . length ) } ${ ( tf2 - ti2 ) . toFixed ( 3 ) } ms` )
3742}
3843
3944benchmarkSearch ( 'simple non-existent pattern' , '\t' , null )
4045benchmarkSearch ( 'complex non-existent pattern' , '123|456|789' , null )
4146benchmarkSearch ( 'simple existing pattern' , 'jkl' , { start : { row : 0 , column : 12 } , end : { row : 0 , column : 15 } } )
42- benchmarkSearch ( 'complex existing pattern' , 'j\\w+' , { start : { row : 0 , column : 12 } , end : { row : 0 , column : 15 } } )
47+ benchmarkSearch ( 'complex existing pattern' , 'j\\w+' , { start : { row : 0 , column : 12 } , end : { row : 0 , column : 15 } } )
48+
49+
50+ console . log ( '\n text-buffer finished \n' )
0 commit comments