* Allocate a new string for fast concatenation: lcName = FSTRNEW(nSize) -- Allocate a new string of default nSize (can be 0) * Note: lcName is a placeholder. It's not the real data. Use FSTRDATA() to get the real data * Fast insert string before: FSTRBEF("new text to prepend", lcName) * Fast insert string after: FSTRAFT(lcName, "new text to append") * Fast arbitrary insert: FSTRMID(lcName, nStartingChar, "new text to insert") * Get the length FSTRLEN(lcName) * Reset for continued use FSTRZAP(lcName) * Release memory associated with the lcName variable FSTRFREE(lcName) * Delete a portion FSTRDEL(lcName, nStart, nLength) * Perform a CHRTRAN() FSTRCHRTRAN(lcName, cSearchString, cReplaceString) * Extract a portion lcString = FSTRSUBSTR(lcName, nStart, nLength) * Extract it all lcString = FSTRDATA(lcName[, .t.]) && .t. -- Delete after extract?Example use:
lcName = FRSTNEW() FOR lnPass = 1 to 5 RAND(0) lnSeconds2 = SECONDS() FOR lnI = 1 to 300000 DO CASE CASE lnI % 3 = 0 * Prepend FSTRBEF(TRANSFORM(lnI), lcName) CASE lnI % 3 = 1 * Append FSTRAFT(lcName, TRANSFORM(lnI)) OTHERWISE * Stuff at a random place in the middle FSTRMID(lcName, 1 + INT(RAND() * (FSTRLEN(lcName) - 1)), TRANSFORM(lnI)) ENDCASE NEXT ? "Pass " + TRANSFORM(lnPass), SECONDS() - lnSeconds2 * Save the data * STRTOFILE(FSTRDATA(lcName), SYS(2015) + "_" + TRANSFORM(lnPass) + ".txt") * Reset for the next pass FSTRZAP(lcName) NEXT * Release when finished FSTRFREE(lcName) RELEASE lcNameCompared to a native VFP equivalent example:
lnSeconds = SECONDS() lcName = SPACE(0) FOR lnPass = 1 to 5 RAND(0) lnSeconds2 = SECONDS() FOR lnI = 1 to 300000 DO CASE CASE lnI % 3 = 0 * Prepend lcName = TRANSFORM(lnI) + lcName CASE lnI % 3 = 1 * Append lcName = lcName + TRANSFORM(lnI) OTHERWISE * Stuff at a random place in the middle lcName = STUFF(lcName, 1 + INT(RAND() * (LEN(lcName) - 1)), 0, TRANSFORM(lnI)) ENDCASE NEXT ? "Pass " + TRANSFORM(lnPass), SECONDS() - lnSeconds2 * Save the data * STRTOFILE(lcName, SYS(2015) + "_" + TRANSFORM(lnPass) + ".txt") * Reset for the next pass lcName = SPACE(0) NEXT * Release when finished RELEASE lcName ? "Native VFP", SECONDS() - lnSecondsOn my computer, the above VFP code took:
100,000 -- 20.4 seconds 200,000 -- 63 seconds 300,000 -- 170 secondsFor a control, I took off the concatenation operations and just ran the TRANSFORM(lnI) operations. Those took:
100,000 -- 0.096 seconds 200,000 -- 0.199 seconds 300,000 -- 0.289 secondsIt shows the bulk of the operation in processing is in the string manipulation. I'm curious what the fst*() functions could do.