It is currently Fri May 25, 2018 9:51 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Fast string
PostPosted: Fri Aug 11, 2017 11:51 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 182
+ 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Fri Aug 11, 2017 1:12 pm 
Offline
User
User

Joined: Tue Jun 17, 2014 4:49 pm
Posts: 44
+ 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Fri Aug 11, 2017 3:37 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 1135
Location: germany
I know that I'm somehow "old fashioned", but I think it is upon the developer to understand, at least in a basic form, how strings are working. And if I find such a scenario, I do it like this since 30 years now:

Code:
DisableDebugger

Str.s
Dummy.s
#Text = "1234567890"

Time = ElapsedMilliseconds()

For i=1 To 100000
  Dummy + #Text
  If Len(Dummy) > 2048
    Str + Dummy
    Dummy = ""
  EndIf
Next i
Str + Dummy

MessageRequester("", StrF((ElapsedMilliseconds()-Time)/1000, 3))


While the initial function in the first thread takes me 48 seconds to complete, the 6 additional lines enhanced the speed to be 0.38 seconds. This is simple to use and really helpful. I do it like this all the time when I concatenate lager strings.

It is definitely not the fastest way possible, but solved it for me cross platform and reliable.

Kukulkan


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Fri Aug 11, 2017 3:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 464
Thanks for that example.

I like solutions where things are easy and fast and not only "fastest as possible even hard to implement".

What speed factors do we talk about?
- naive string handling
- Kukulkans less memory mappings method
- fast string builder
(It's about huge strings, isn't it?)

And... I can not see the problem.
Shouldn't it be possible in any situation (CSV, etc.) to guess the max size of the string and use Space() and PokeS?
Another shrink is then one fast memory operation.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Sun Apr 15, 2018 8:25 am 
Offline
User
User

Joined: Mon Jun 23, 2014 1:18 pm
Posts: 26
Just a little fun code, to remember this is still a thing :D

Code:
EnableExplicit

Procedure StringAppend(*sb,string.s)
   Protected size,*Offset
   If *sb
      size=MemorySize(*sb)
      *Offset=size
   EndIf
   size+StringByteLength(string)
   *sb=ReAllocateMemory(*sb,size,#PB_Memory_NoClear)
   PokeS(*sb+*offset,string,-1,#PB_String_NoZero)
   ProcedureReturn *sb
EndProcedure

Procedure.s SBToString(*sb)
   ProcedureReturn PeekS(*sb,MemorySize(*sb)/SizeOf(Character))
EndProcedure

OpenConsole()

Define i
Define s.s="Lalala"
Define *sb=StringAppend(*sb,"Lalala")
#max=100000


Define start=ElapsedMilliseconds()
For i=1 To #max
   s+"La"
Next
Define ende=ElapsedMilliseconds()

PrintN(Str(ende-start)+" - "+Len(s))

start=ElapsedMilliseconds()
For i=1 To #max
   *sb=StringAppend(*sb,"La")
Next
ende=ElapsedMilliseconds()

PrintN(Str(ende-start)+" - "+Len(SBToString(*sb)))

Input()
CloseConsole()


Result
Code:
40733 - 200006
23 - 200006


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Sun Apr 15, 2018 8:52 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1379
Cyllceaux wrote:
Just a little fun code, to remember this is still a thing :D

I have an issue with extremely slow strings, that I posted about here:

viewtopic.php?f=13&t=70568

I'd love to see strings being fast natively, to avoid POKES and memory buffers and mucking around like that.

Shield wrote:
This is not generally a PureBasic "problem"

Technically, no. But if we can write long blocks of code as a "workaround", then such workarounds need to become native.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fast string
PostPosted: Tue May 01, 2018 2:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Mar 10, 2013 3:01 pm
Posts: 523
Location: Portugal
+1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye