I have recently been fiddling with text and list a lot, for a project I've slowly been developing alone.
As you can see, I ran two seperate test on these; seeing how much cpu was use uppon 100 thousand runs and 1 million runs simultaneously.
I'm quite pleased with these results, uppon my first test it resulted in almost 9 total cpu used for the Reverse() proc(per 100 thousand calls). I went ahead and re-wrote the proc and retested to a very pleasing drop in the cpu usage.
proc
Reverse(var/T as text)
var/newT=""
var/i=-1
while(lentext(T)>lentext(newT))
newT+=copytext(T,i)
i--
return newT
Reverse_List(var/list/L)
var/a=L.len
var/list/b=new()
while(a)
b.Add(L[a])
a--
return b
list2text(var/list/L,var/a as text)
if(!L) return
if(!a) a=","
var/T=""
for(var/l in L)
if(!T) T+="[l]"
else T+="[a][l]"
if(findtextEx(T,a,1,2)) T=("EMPTY"+T)
if(findtextEx(T,a,-1)) T=(T+"[a]EMPTY")
while(findtextEx(T,"[a][a]")) T=replaceText(T,"[a][a]","[a]EMPTY[a]")
return T
text2list(var/T as text,var/a as text)
if(!T) return
if(!a) a=","
var/list/L=new()
if(!findtextEx(T,a)) {L.Add(T); return L}
if(findtextEx(T,a,1,2)) T=("EMPTY"+T)
if(findtextEx(T,a,lentext(T))) T=(T+"EMPTY")
while(findtextEx(T,"[a][a]")) T=replaceText(T,"[a][a]","[a]EMPTY[a]")
while(findtextEx(T,a,1))
var/f=findtextEx(T,a,1)
var/i=copytext(T,1,f)
L.Add(i)
T=copytext(T,f+1)
return L
The above of the proc codes I used for these test.
Below is the test I used.
mob
verb
ListPreformanceTest()
var/list/L=list("What","You","Say","ToMe","kk")
var/i=100000//altered this to 1mil for other test.
while(i)
i--
text2list(Reverse(list2text(Reverse_List(L))))
I included 5 text entries into a list, equaling to 16 total characters.
I would like to have input from other programmers to help me correct anything that'd allow for better preformance without taking away functionality.
I would also like others to attempt their own test and share with me their results, so that I can see how it effects others.
The only thing I tested was:
/proc/Reverse_List 5.349 5.417 5.625 1000000
If I got all indexes right then code should work right away.