Seite 2 von 2

Verfasst: 28.04.2006 00:03
von mk-soft
@ts-soft,

top routine :allright:

[Edit]

Code: Alles auswählen

#r = 100000

Debug "Start Test..."
time1 = ElapsedMilliseconds()
For ri = 1 To #r

Text.s = "Hallo,           wie             geht's?"
neu.s = ""

For i = 1 To Len(text)
  If Mid(text, i, 1) = " "
    If leer = #False
      leer = #True
      neu + Mid(text, i, 1)
    EndIf
  Else
    leer = #False
    neu + Mid(text, i, 1)
  EndIf
Next i

Next

time1 = ElapsedMilliseconds() - time1

;----------------------------
time2 = ElapsedMilliseconds()
For ri = 1 To #r

Text.s = "Hallo,           wie             geht's?"

While FindString(Text, "  ", 1)
  Text = ReplaceString(Text,"  "," ")
Wend

Next

time2 = ElapsedMilliseconds() - time2

;----------------------------
time3 = ElapsedMilliseconds()
For ri = 1 To #r

Text.s = "Hallo,           wie             geht's?"

*sText.Byte = @Text
*dText.Byte = @Text
Repeat
  *dText\b = *sText\b
  If *dText\b = ' '
    While *sText\b = ' '
      *sText+1
    Wend
  Else
    *sText+1
  EndIf
  *dText+1
Until *sText\b = 0
*dText\b = *sText\b

Next

time3 = ElapsedMilliseconds() - time3

;----------------------------
time4 = ElapsedMilliseconds()
For ri = 1 To #r

  Text.s = "Hallo,           wie             geht's?"

  *wert.byte = @Text
  Text2.s = Space(Len(Text))
  *wert2.byte = @Text2
  Repeat
    If *wert\b = 32
      *wert + 1
      *wert2 + 1
      While *wert\b = 32
        *wert + 1
      Wend
    EndIf
    *wert2\b = *wert\b
    *wert + 1
    *wert2 + 1
  Until *wert\b = 0
  
Next

time4 = ElapsedMilliseconds() - time4

result.s = "mk-soft: " + Str(time1)+" / Kiffi: "+Str(time2)+" / Deeem2031: "+Str(time3)+" / ts-soft: "+Str(time4)

MessageRequester("Result", result)

fast so schnell wie Kiffi´s

FF :allright:

Verfasst: 28.04.2006 00:08
von mk-soft
@Deeem2031,

Sorry, habe jetzt ohne Debugger getestet. DU BIST SIEGER :allright: (bis jetzt) <)

Verfasst: 28.04.2006 00:39
von ts-soft
mk-soft hat geschrieben:@ts-soft,

top routine :allright:
Danke, aber Deeem seine ist schneller
mk-soft hat geschrieben: fast so schnell wie Kiffi´s

FF :allright:
das kann nicht stimmen, nur Deeem ist etwas schneller :wink:

Hier der Komplettest, meins ohne Procedure usw.

Code: Alles auswählen

#r = 100000
 
time1 = ElapsedMilliseconds()
 
For ri = 1 To #r
 
  Text.s = "Hallo,           wie             geht's?"
  neu.s = ""
 
  For i = 1 To Len(text)
    If Mid(text, i, 1) = " "
      If leer = #False
        leer = #True
        neu + Mid(text, i, 1)
      EndIf
    Else
      leer = #False
      neu + Mid(text, i, 1)
    EndIf
  Next i
 
Next
 
time1 = ElapsedMilliseconds() - time1
 
time2 = ElapsedMilliseconds()
 
For ri = 1 To #r
 
  Text.s = "Hallo,           wie             geht's?"
 
  While FindString(Text, "  ", 1)
    Text = ReplaceString(Text,"  "," ")
  Wend
 
Next
 
time2 = ElapsedMilliseconds() - time2
 
time3 = ElapsedMilliseconds()
 
For ri = 1 To #r
 
  Text.s = "Hallo,           wie             geht's?"
 
  *sText.Byte = @Text
  *dText.Byte = @Text
  Repeat
    *dText\b = *sText\b
    If *dText\b = ' '
      While *sText\b = ' '
        *sText+1
      Wend
    Else
      *sText+1
    EndIf
    *dText+1
  Until *sText\b = 0
  *dText\b = *sText\b
 
Next
 
time3 = ElapsedMilliseconds() - time3
 
 
time4 = ElapsedMilliseconds()
For ri = 1 To #r
 
  Text.s = "Hallo,           wie             geht's?"
 
  *wert.byte = @Text
  Text2.s = Space(Len(Text))
  *wert2.byte = @Text2
  Repeat
    If *wert\b = 32
      *wert + 1
      *wert2 + 1
      While *wert\b = 32
        *wert + 1
      Wend
    EndIf
    *wert2\b = *wert\b
    *wert + 1
    *wert2 + 1
  Until *wert\b = 0 
 
Next
time4 = ElapsedMilliseconds() - time4
 
MessageRequester("",Str(time1)+" "+Str(time2)+" "+Str(time3)+" "+Str(time4))

Verfasst: 28.04.2006 09:45
von der-sigi
Hallo ihr Fleißigen ...

klasse, was da alles rausgekommen ist. Dankeschön.

Ich habe das seither mit 'ner Schleife gelöst, ähnlich wie mk-soft und dabei halte ich mich wie Kiffi mit "Ich lege i. A. mehr Wert auf Code, den ich auch nach langer Zeit auf Anhieb lesen kann." Ich meine damit nur was anderes als Kiffi (grins), denn die Schleife ist mir lieber als proprietärer Kode, der schwierig (wenn man es nicht kennt) in andere Sprachen zu übersetzen ist - eine Schleife kann man beispielsweise direkt übernehmen und es funktioniert.

Nochmal Danke
und viele Grüße
Sigi

Verfasst: 28.04.2006 10:08
von Karl
Bitte jetzt ´ne Analyse in 0-Notation :D

Gruß Karl

Verfasst: 28.04.2006 10:27
von Exabot

Code: Alles auswählen

Procedure.s RemoveDuplicateBytes( Text.s, Byte.c )
  *sText.Byte = @Text 
  *dText.Byte = @Text 
  Repeat 
    *dText\b = *sText\b 
    If *dText\b = Byte
      While *sText\b = Byte
        *sText+1 
      Wend 
    Else 
      *sText+1 
    EndIf 
    *dText+1 
  Until *sText\b = 0 
  *dText\b = *sText\b 
  ProcedureReturn Text
EndProcedure
So ists universeller,
das war der Vorteil von Kiffis Code

Gruss
Spider