Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Re: Performance experiment ( was: SQL string utility ) (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Linux folderitem visible
Next thread: Charlie Brown and the ball - me and RB's data bound controls


SQL string utility   -   Craig Boyd
  Re: Performance experiment ( was: SQL string utility )   -   Kem Tekinay
    Performance experiment ( was: SQL string utility )   -   Eric de La Rochette

Re: Performance experiment ( was: SQL string utility )
Date: 23.09.11 20:14 (Fri, 23 Sep 2011 15:14:42 -0400)
From: Kem Tekinay
First, I should clarify something. I used the abbreviation "ms" in my posts to mean "microseconds" whereas you are properly using it to mean "milliseconds". Anyone comparing the two posts should make the mental adjustment.

I was able to reproduce your results, with one small modification. Instead of a using a random string, I generate the same string for each test.

dim s as string
for i as integer = 0 to 32
s = s + chr( i )
next i

for i as integer = 1 to 10
s = s + s
next i

return s

The difference here in a compiled app is much smaller though at about 15.1 ms vs. 15.4 ms. Still, it's pretty consistent between runs.

I'd love to hear RS's comments on this.

On Sep 23, 2011, at 8:34 AM, Eric de La Rochette wrote:

>
> This morning, I was in an experimenting mood... So I decide to experiment with RS:
>
> I ran the following code:
>
> Const kIteration = 100
> Dim theSource As String = Get32KString
> Dim theTotalTime As Double
>
> For z As Integer = 1 to kIteration
> Dim theStart As Double = Microseconds
>
> Dim Chars() As String = theSource.Split( "" )
> Dim t As integer = Chars.Ubound
> For i As Integer = 0 To t
> If Asc( Chars( i ) ) < 32 Then Chars( i ) = ""
> Next
> Dim s1 As String = Join( Chars, "" )
>
> theTotalTime = Microseconds - theStart + theTotalTime
> Next z
>
> MsgBox "Temps: " + Str( theTotalTime / 1000 / kIteration )
>
> And I got 42 ms as a result on my MacBook ( 2006 )
>
> Const kIteration = 100
> Dim theSource As String = Get32KString
> Dim theTotalTime, theStart As Double
> Dim Chars(), s1 As String
> Dim i,t AS Integer
>
> For z As Integer = 1 to kIteration
> theStart = Microseconds
>
> Chars() = theSource.Split( "" )
> t = Chars.Ubound
> For i = 0 To t
> If Asc( Chars( i ) ) < 32 Then Chars( i ) = ""
> Next
> s1 = Join( Chars, "" )
>
> theTotalTime = Microseconds - theStart + theTotalTime
> Next z
>
> MsgBox "Temps: " + Str( theTotalTime / 1000 / kIteration )
>
> This code, took 52 ms to run.
>
> I test this around a dozen times and always get the same result. Does it mean that defining local variables each time the code is looping is faster than defining them once and for all in a method? Or does it have to do with the code accessing a variable within the same level of scope than its current scope ( the 'z' For...Next loop in this case ) is faster than accessing a variable defined on a higher level?
>
> --
> Eric.
> PS: the Get3KString() function return a 32K string filled with random characters within the 0-255 range.
> The test was done in the debugger and w/o any pragma.
>
> On Sep 22, 2011, at 21:11 , Kem Tekinay wrote:
>
>> dim mb as MemoryBlock = s3
>> dim chars() as string
>> dim l as integer = mb.Size - 1
>> for i as integer = 0 to l
>> dim b as integer = mb.Byte( i )
>> if b > 31 then chars.Append chr( b )
>> next i
>> s3 = join( chars, "" )
>
> --
> Eric.
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

Performance experiment ( was: SQL string utility )
Date: 23.09.11 13:34 (Fri, 23 Sep 2011 12:34:56 +0000)
From: Eric de La Rochette
This morning, I was in an experimenting mood... So I decide to experiment with RS:

I ran the following code:

Const kIteration = 100
Dim theSource As String = Get32KString
Dim theTotalTime As Double

For z As Integer = 1 to kIteration
Dim theStart As Double = Microseconds

Dim Chars() As String = theSource.Split( "" )
Dim t As integer = Chars.Ubound
For i As Integer = 0 To t
If Asc( Chars( i ) ) < 32 Then Chars( i ) = ""
Next
Dim s1 As String = Join( Chars, "" )

theTotalTime = Microseconds - theStart + theTotalTime
Next z

MsgBox "Temps: " + Str( theTotalTime / 1000 / kIteration )

And I got 42 ms as a result on my MacBook ( 2006 )

Const kIteration = 100
Dim theSource As String = Get32KString
Dim theTotalTime, theStart As Double
Dim Chars(), s1 As String
Dim i,t AS Integer

For z As Integer = 1 to kIteration
theStart = Microseconds

Chars() = theSource.Split( "" )
t = Chars.Ubound
For i = 0 To t
If Asc( Chars( i ) ) < 32 Then Chars( i ) = ""
Next
s1 = Join( Chars, "" )

theTotalTime = Microseconds - theStart + theTotalTime
Next z

MsgBox "Temps: " + Str( theTotalTime / 1000 / kIteration )

This code, took 52 ms to run.

I test this around a dozen times and always get the same result. Does it mean that defining local variables each time the code is looping is faster than defining them once and for all in a method? Or does it have to do with the code accessing a variable within the same level of scope than its current scope ( the 'z' For...Next loop in this case ) is faster than accessing a variable defined on a higher level?