PeekS() vs Left()

Everything else that doesn't fall into one of the other PB categories.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

PeekS() vs Left()

Post 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
I like logic, hence I dislike humans but love computers.
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post 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.
Pro-Gamer, Programmer, Pro-Grammer
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Hehe, yeah it does.
It's not very much faster but a little, and I love speed! :D
Last edited by Joakim Christiansen on Thu Oct 12, 2006 8:20 am, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: PeekS() vs Left()

Post by traumatic »

...never ever do any performance tests with enabled debugger...
Last edited by traumatic on Thu Oct 12, 2006 8:25 am, edited 2 times in total.
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: PeekS() vs Left()

Post 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*
I like logic, hence I dislike humans but love computers.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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
I like logic, hence I dislike humans but love computers.
thamarok
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 06, 2006 1:37 pm

Post 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....
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post 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()?
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Don't forget that unicode support means that you cannot assume that 1byte = 1 character.
Post Reply