File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -247,20 +247,27 @@ $(function () {
247247 let count = 1 + Math . floor ( Math . random ( ) * 79 ) ;
248248 byteCount += count + 2 ;
249249 let data = new Uint8Array ( count + 2 ) ;
250- for ( let i = 0 ; i < count ; i ++ ) {
250+ data [ 0 ] = 0x0A ; // \n
251+ for ( let i = 1 ; i < count + 1 ; i ++ ) {
251252 data [ i ] = 0x61 + Math . floor ( Math . random ( ) * ( 0x7A - 0x61 ) ) ;
252253 }
253- data [ i ++ ] = 0xA ; // \n
254- data [ i ] = 0xD ; // \r
254+ // End each line with \r so the cursor remains constant, this is what ls/tree do and improves
255+ // performance significantly due to the cursor DOM element not needing to change
256+ data [ data . length - 1 ] = 0x0D ; // \r
255257 testData . push ( data ) ;
256258 }
257259 for ( let i = 0 ; i < 1024 ; i ++ ) {
258260 for ( const d of testData ) {
259261 term . write ( d ) ;
260262 }
261263 }
262- term . write ( `\r\nWrote ${ byteCount } kB in ${ Math . round ( ( performance . now ( ) - start ) * 1000 ) } ms (${ isWebglEnabled ? 'webgl' : 'canvas' } renderer)` ) ;
263- term . prompt ( ) ;
264+ // Wait for all data to be parsed before evaluating time
265+ term . write ( '' , ( ) => {
266+ let time = Math . round ( performance . now ( ) - start ) ;
267+ let mbs = ( ( byteCount / 1024 ) * ( 1 / ( time / 1000 ) ) ) . toFixed ( 2 ) ;
268+ term . write ( `\n\r\nWrote ${ byteCount } kB in ${ time } ms (${ mbs } MB/s) using the (${ isWebglEnabled ? 'webgl' : 'canvas' } renderer)` ) ;
269+ term . prompt ( ) ;
270+ } ) ;
264271 } ,
265272 description : 'Simulate a lot of data coming from a process'
266273 }
You can’t perform that action at this time.
0 commit comments