Symptom
The performance gets low when adding strings in the loop statement. In the following case, time consumes up to 80 second.
string ls_output, ls_data="PB2017R3 Test Data " long ll_loop, ll_cpu ll_cpu = CPU ( ) FOR ll_loop = 1 to 100000 ls_output = ls_output + ls_data NEXT MessageBox ('', "BlobEdit time: " + String ( CPU() - ll_cpu, "#,##0" ) + "ms" )
Environment
PowerBuilder 2017 or later
Cause
This is a PowerBuilder known issue, the performance of processing strings is low.
Solution
Solution #1: Use Blob to process strings. For example, the following code consumes only 1 second.
blob{100000} lblb_blob string ls_output long ll_loop, ll_pos = 2, ll_cpu ll_cpu = CPU ( ) FOR ll_loop = 1 to 100000 ll_pos = BlobEdit (lblb_blob, ll_pos - 1, "PB2017R3 Test Data ", EncodingANSI!) NEXT ls_output = String (lblb_blob, EncodingANSI!) MessageBox ( "","BlobEdit time: " + String ( CPU() - ll_cpu, "#,##0" ) + "ms" )
Solution #2: Write an API with C++ to add strings together.