Example for the test
I tested:
your example : time 0.367
JoinList : time 0.001 (use CopyMemoryString)
I changed to Console Output to be sure it is not a debugger problem! Same result!
Can you confirm this result?
Code: Select all
EnableExplicit
Define Result$
Define *m
Define i, StartTime
Define NewList ListStr.s()
#StrSize = 70 ; string length
#Count = 5000 ; number of lines
*m = AllocateMemory(#StrSize * 2 + 4)
If Not *m
End
EndIf
RandomSeed(123456789)
Procedure Filling(*c.Character, List ListStr.s())
Protected i, j, *c0
*c0 = *c
For i = 1 To #Count
*c = *c0
For j = 1 To #StrSize
*c\c = Random(122, 65)
*c + 2
Next
AddElement(ListStr())
ListStr() = PeekS(*c0)
Next
EndProcedure
Procedure.s JoinList(List lst.s(), Separator$, *IOutLen.Integer=0)
; ============================================================================
; NAME: JoinList
; DESC: Join all ListElements to a single String
; VAR(lst.s()) : The String List
; VAR(Separator$) : A separator String
; VAR(*IOutLen) : Pointer to a IntVar for optional return of Stringlenght
; RET.s: the String
; ============================================================================
Protected ret$
Protected I, L, N, lenSep
Protected *ptr
;lenSep = MemoryStringLength(@Separator$)
lenSep = Len(Separator$)
N = ListSize(lst())
Debug "ListLength = " + N
If N
; ----------------------------------------
; With Separator
; ----------------------------------------
ForEach lst()
L = L + Len(lst())
Next
L = L + (N-1) * lenSep
ret$ = Space(L)
*ptr = @ret$
If lenSep > 0
ForEach lst()
If lst()<>#Null$
CopyMemoryString(lst(), @*ptr)
EndIf
I + 1
If I < N
CopyMemoryString(Separator$, @*ptr)
EndIf
Next
Else
; ----------------------------------------
; Without Separator
; ----------------------------------------
ForEach lst()
If lst()<>#Null$
CopyMemoryString(lst(), @*ptr)
EndIf
Next
EndIf
EndIf
If *IOutLen
*IOutLen\i = L
EndIf
ProcedureReturn ret$
EndProcedure
Filling(*m, ListStr())
FreeMemory(*m)
OpenConsole()
; Output 5 strings showing that the strings exist
ResetList(ListStr())
For i = 1 To 5
NextElement(ListStr())
PrintN(ListStr())
Next
DisableDebugger
StartTime = ElapsedMilliseconds()
ForEach ListStr()
Result$ + ListStr()
;Result$ = JoinList(ListStr(),"")
Next
StartTime = (ElapsedMilliseconds() - StartTime)
EnableDebugger
; Debug FormatNumber(StartTime / 1000, 3, ".", "") ; seconds
PrintN(FormatNumber(StartTime / 1000, 3, ".", "")) ; seconds
PrintN("")
PrintN("press any key!")
Input()