;========================================================================================================================================== ; How to get one row from dim2 array into new dim2 array? ; ; Simple profiling using three methods. ; ; (c)Detlev Dalitz.20120206. ;========================================================================================================================================== ; Prepare test scenario. ; Define the row number of the row, which should be fetched out of the given dim2 array. intRowGet = 123 ; Create source test array. intRows = 250 intCols = 200 intRowLast = intRows - 1 intColLast = intCols - 1 arrSource = ArrDimension (intRows, intCols) ArrInitialize (arrSource, "d a t a") For intRow = 0 To intRowLast arrSource[intRow, 0] = intRow ; Fill first cell in row with the row number. arrSource[intRow, intColLast] = "last cell in row" ; Fill last cell with some text. Next ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method 1. ;------------------------------------------------------------------------------------------------------------------------------------------ intTicksStart = GetTickCount () ; Define target dim2 array. arrTarget = ArrDimension (1, intCols) ; Transfer data from source array to target array. intColLast = intCols - 1 For intCol = 0 To intColLast arrTarget[0, intCol] = arrSource[intRowGet, intCol] Next intTicksDiff = GetTickCount () - intTicksStart ; ~ 50 ticks. strMsgTitle = "Result Method 1 | Ticks = " : intTicksDiff strMsgText = arrTarget[0, 0] : "|" : arrTarget[0, 1] : "| ... |" : arrTarget[0, intColLast - 1] : "|" : arrTarget[0, intColLast] Pause (strMsgTitle, strMsgText) ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method 2. ;------------------------------------------------------------------------------------------------------------------------------------------ intTicksStart = GetTickCount () ; Unload dim2 array. strFileTemp = FileCreateTemp ("WB") intBytesWritten = ArrayFilePutCSV (strFileTemp, arrSource, ",", @TRUE, 0) arrTemp = ArrayFileGet (strFileTemp) intBytesWritten = FilePut (strFileTemp, arrTemp[intRowGet]) ; Create target dim2 array with the one row we want to have. arrTarget = ArrayFileGetCSV (strFileTemp, 0) ; Clean up. blnResult = FileDelete (strFileTemp) Drop (arrTemp, strFileTemp) intTicksDiff = GetTickCount () - intTicksStart ; ~ 1600 ticks. strMsgTitle = "Result Method 2 | Ticks = " : intTicksDiff strMsgText = arrTarget[0, 0] : "|" : arrTarget[0, 1] : "| ... |" : arrTarget[0, intColLast - 1] : "|" : arrTarget[0, intColLast] Pause (strMsgTitle, strMsgText) ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method 3. ;------------------------------------------------------------------------------------------------------------------------------------------ intTicksStart = GetTickCount () ; Duplicate dim2 array. strFileTemp = FileCreateTemp ("WB") intBytesWritten = ArrayFilePutCSV (strFileTemp, arrSource, ",", @TRUE, 0) arrTarget = ArrayFileGetCSV (strFileTemp, 0) ; Clean up. blnResult = FileDelete (strFileTemp) Drop (strFileTemp) ; Remove all other rows but the one we want to have. intRow = intRowGet + 1 While ArrInfo (arrTarget, 1) > intRow ArrayRemove (arrTarget, intRow, 1) EndWhile While ArrInfo (arrTarget, 1) > 1 ArrayRemove (arrTarget, 0, 1) EndWhile ; Target array has one row left here. intTicksDiff = GetTickCount () - intTicksStart ; ~ 3300 ticks. strMsgTitle = "Result Method 3 | Ticks = " : intTicksDiff strMsgText = arrTarget[0, 0] : "|" : arrTarget[0, 1] : "| ... |" : arrTarget[0, intColLast - 1] : "|" : arrTarget[0, intColLast] Pause (strMsgTitle, strMsgText) ;------------------------------------------------------------------------------------------------------------------------------------------ ; Summary. ; ; The simplest method 1 is the most effective method, at least within this test scenario. ;------------------------------------------------------------------------------------------------------------------------------------------ :CANCEL Exit