Just done some rough code to check out a 200,000 byte string (too painful waiting for 2M byte string to process)
Sample below shows huge benefit in the file approach. The only thing I can think of right now to improve it further would be to do it in C++ or similar where you can easily treat the string as an array - pass everything around by ref and should be faster - but it seems the file approach is fast enough. Substr 200,00 bytes - 1.822 seconds StrtoFile 200,00 bytes - 0.001 seconds StrtoFile 10,000,00 bytes - 0.005 seconds *- Substr loop x = REPLICATE("Y", 200000) lnsec = SECONDS() FOR n = 1 TO LEN(x) y = SUBSTR(x,n,1) ENDFOR ? SECONDS() - m.lnSec && 1.822 *------------------------- *- File approach 200,000 bytes *------------------------- lnsec = SECONDS() =STRTOFILE(x, "c:\temp\test.txt") lnFile = FOPEN("c:\temp\test.txt", 2) lnChrs = FSEEK(m.lnFile,0,2) ? lnChrs =FSEEK(m.lnFile, 0, 0) FOR lnChr = 1 TO m.lnChrs y = FREAD(m.lnFile, 1) ENDFOR =FCLOSE(m.lnFile) ? SECONDS() - m.lnSec && 0.001 secs *------------------------- *- File approach 10,000,000 bytes *------------------------- x = REPLICATE("Y", 10000000) lnsec = SECONDS() =STRTOFILE(x, "c:\temp\test.txt") lnFile = FOPEN("c:\temp\test.txt", 2) lnChrs = FSEEK(m.lnFile,0,2) ? lnChrs =FSEEK(m.lnFile, 0, 0) FOR lnChr = 1 TO m.lnChrs y = FREAD(m.lnFile, 1) ENDFOR =FCLOSE(m.lnFile) ? SECONDS() - m.lnSec && 0.005 secs -----Original Message----- From: ProfoxTech [mailto:profoxtech-boun...@leafe.com] On Behalf Of Joe Yoder Sent: Saturday, 10 September 2016 3:33 PM To: profoxt...@leafe.com Subject: Processing a long character string one character at a time I have a routine that processes each character in a file. The file I am working with is over 2 million characters long. I pull it into a memory variable with filetostr and then process each character with the substr command. Apparently substr has problems when dealing with a long string as the process is painfully slow. I suspect that I will be better off using the low level file routines to read one character at a time but thought maybe someone knows of a way to speed up the approach I am using now. Thanks in advance, Joe --- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html --- [excessive quoting removed by server] _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/002a01d20b38$efc49e40$cf4ddac0$@ozemail.com.au ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.