Page 1 of 1

PeekS() vs Left()

Posted: Thu Oct 12, 2006 8:08 am
by Joakim Christiansen
Both very fast, but PeekS() is faster! :wink:
Maybe it should be noted in the helpfile?

Code: Select all

Test.s = "Hello you damn bitch!!"
New.s

For u=0 To 10
  Time = ElapsedMilliseconds()
  For i=0 To 999999
    New = PeekS(@Test,10)
  Next
  Debug "PeekS() delay: "+Str(ElapsedMilliseconds()-Time)
  
  Time = ElapsedMilliseconds()
  For i=0 To 999999
    New = Left(Test,10)
  Next
  Debug "Left() delay: "+Str(ElapsedMilliseconds()-Time)
Next
Any other commands we should test? :P

Posted: Thu Oct 12, 2006 8:18 am
by CadeX
Interesting... *Quickly modifies all of his programs code*, Like...Yeah...Everyone knew....uh...that! Yeah!

Lol, thanks for pointing that out... I guess it does make left kinda useless.

Posted: Thu Oct 12, 2006 8:19 am
by Joakim Christiansen
Hehe, yeah it does.
It's not very much faster but a little, and I love speed! :D

Re: PeekS() vs Left()

Posted: Thu Oct 12, 2006 8:20 am
by traumatic
...never ever do any performance tests with enabled debugger...

Re: PeekS() vs Left()

Posted: Thu Oct 12, 2006 8:20 am
by Joakim Christiansen
traumatic wrote:...never ever do any performance tests with enabled debugger...
Oh, I forgot about that.
Hmm, let's see how it's without it then... *testing again*

Posted: Thu Oct 12, 2006 8:23 am
by Joakim Christiansen
Disable debugger for real test.

Code: Select all

Test.s = "Hello you damn bitch!!"
New.s
String.s

For u=0 To 10
  Time = ElapsedMilliseconds()
  For i=0 To 999999
    New = PeekS(@Test,10)
  Next
  String + "PeekS() delay: "+Str(ElapsedMilliseconds()-Time) + #CRLF$
 
  Time = ElapsedMilliseconds()
  For i=0 To 999999
    New = Left(Test,10)
  Next
  String + "Left() delay: "+Str(ElapsedMilliseconds()-Time) + #CRLF$
Next

MessageRequester("Result",String)
Still faster! :D

Posted: Thu Oct 12, 2006 8:24 am
by thamarok
Disable debugger and see the results:

Code: Select all

Test.s = "Hello you damn bitch!!" 
New.s 

For u=0 To 5 
  Time = ElapsedMilliseconds() 
  For i=0 To 999999 
    New = PeekS(@Test,10) 
  Next 
  MessageRequester("","PeekS() delay: "+Str(ElapsedMilliseconds()-Time) )
  
  Time = ElapsedMilliseconds() 
  For i=0 To 999999 
    New = Left(Test,10) 
  Next 
  MessageRequester("","Left() delay: "+Str(ElapsedMilliseconds()-Time) )
Next
PeekS seems just very little faster....

Posted: Thu Oct 12, 2006 11:21 am
by remi_meier
And now we read the manual a bit more carefully.....
Left() is safe even with invalid length, like negative ones :roll:

Edit: And btw, how would you do things like Left(Trim(s.s)) with PeekS()?

Posted: Thu Oct 12, 2006 12:45 pm
by GedB
Don't forget that unicode support means that you cannot assume that 1byte = 1 character.