I
Ian Stewart
Guest
I have noticed in Progress (10.4) that repeated string concatenation can be very slow. For example in the following code.
DEF VAR i AS INT NO-UNDO.
DEF VAR c AS LONGCHAR NO-UNDO.
DO i = 1 TO 1000000:
c = c + STRING(i MOD 10).
END.
From my experience in Java, I think the problem is that each time we are concatenating, we are copying c which is an O(n) operation, so the whole procedure is O(n^2). Java provides the StringBuilder class to solve this problem.
Is my analysis of the problem correct? And if so, is there a solution?
Continue reading...
DEF VAR i AS INT NO-UNDO.
DEF VAR c AS LONGCHAR NO-UNDO.
DO i = 1 TO 1000000:
c = c + STRING(i MOD 10).
END.
From my experience in Java, I think the problem is that each time we are concatenating, we are copying c which is an O(n) operation, so the whole procedure is O(n^2). Java provides the StringBuilder class to solve this problem.
Is my analysis of the problem correct? And if so, is there a solution?
Continue reading...