import * as assert from 'assert' ; import { Utility } from '../src/misc/utility' ; import { DecodeZesaruxRegisters } from '../src/remotes/zesarux/decodezesaruxdata' ; /**
 * The tests here are not really unit tests but meant to check some
 * functionality or to do performance tests.
 */ function suite_hide ( name , func ) { } suite_hide ; function test_hide ( name , func ) { } test_hide ; suite_hide ( 'Miscellaneous' , ( ) => { suite ( 'Performance' , ( ) => { test_hide ( 'Array vs Map' , ( ) => { const itemCount = 65536 * 10 ; const accessCount = 10000000 ; const step = 20 ; const denseArr = new Array < any > ( itemCount ) ; for ( let i = 0 ; i < itemCount ; i ++ ) { denseArr [ i ] = new Object ( ) ; } let k = 0 ; const timeDenseArr = Utility . measure ( ( ) => { denseArr [ k ] ; k += step ; if ( k >= itemCount ) k == 0 ; } , accessCount ) ; console . log ( '\nPerformance: Array vs. Map' ) ; console . log ( 'itemCount=' + itemCount + ', accessCount=' + accessCount ) ; console . log ( 'Dense Array: ' + timeDenseArr + 'ms' ) ; const sparseArr = new Array < any > ( ) ; for ( let i = 0 ; i < itemCount ; i += step ) { sparseArr [ i ] = new Object ( ) ; } k = 1 ; const timeSparseArrHoles = Utility . measure ( ( ) => { sparseArr [ k ] ; k += step ; if ( k >= itemCount ) k == 0 ; } , accessCount ) ; console . log ( 'Sparse Array, accessing holes: ' + timeSparseArrHoles + 'ms' ) ; k = 0 ; const timeSparseArrNoHoles = Utility . measure ( ( ) => { sparseArr [ k ] ; k += step ; if ( k >= itemCount ) k == 0 ; } , accessCount ) ; console . log ( 'Sparse Array, no holes: ' + timeSparseArrNoHoles + 'ms' ) ; k = 0 ; const step2 = step / 2 ; const timeSparseArrBoth = Utility . measure ( ( ) => { sparseArr [ k ] ; k += step2 ; if ( k >= itemCount ) k == 0 ; } , accessCount ) ; console . log ( 'Sparse Array, both: ' + timeSparseArrBoth + 'ms' ) ; const map = new Map < number , any > ( ) ; for ( let i = 0 ; i < itemCount ; i ++ ) { map . set ( i , new Object ( ) ) ; } k = 0 ; const timeMap = Utility . measure ( ( ) => { map . get ( k ) ; k += 10 ; if ( k >= itemCount ) k == 0 ; } , accessCount ) ; console . log ( 'Map: ' + timeMap + 'ms' ) ; assert . ok ( true ) ; } ) ; test ( 'Performance decode register' , ( ) => { const count = 300000 ; const decoder = new DecodeZesaruxRegisters ( 8 ) ; const line = "PC=812c SP=8418 AF=03ff BC=02ff HL=99a2 DE=ffff IX=ffff IY=5c3a AF'=0044 BC'=174b HL'=107f DE'=0006 I=00 R=2c  F=SZ5H3PNC F'=-Z-- -P-- MEMPTR=0000 IM0 IFF-- VPS: 0 MMU=80008001000a000b0004006400000001" ; const timeWithIndexDE = Utility . measure ( ( ) => { decoder . parseDE ( line ) ; } , count ) ; console . log ( '\nPerformance: decode register' ) ; console . log ( 'parseDE: WithIndex=' + timeWithIndexDE + 'ms' ) ; const timeWithIndexPC = Utility . measure ( ( ) => { decoder . parseDE ( line ) ; } , count ) ; console . log ( 'parsePC: WithIndex=' + timeWithIndexPC + 'ms' ) ; const timeWithSearchDE = Utility . measure ( ( ) => { ( decoder as any ) . deIndex = - 1 ; decoder . parseDE ( line ) ; } , count ) ; console . log ( 'parseDE: WithSearch=' + timeWithSearchDE + 'ms' ) ; const timeWithSearchPC = Utility . measure ( ( ) => { ( decoder as any ) . pcIndex = - 1 ; decoder . parsePC ( line ) ; } , count ) ; console . log ( 'parsePC: WithSearch=' + timeWithSearchPC + 'ms' ) ; assert . ok ( true ) ; } ) ; } ) ; } ) ;