Thread slow than process via the example project

Example Projects\Console\Multiprocessing\WordCounterGUI.xojo_binary_project

threaded running it,takes 15 seconds,and the UI slow[ I can’t understand why crash mainUI]
and using process,very fast. only 1 seconds.
don’t know why.

btw: I just run,not building.

Dim count As Integer
Dim wordLength As Integer

Dim char As String
Dim textLen As Integer = mText.Len
For i As Integer = 1 To textLen
char = mText.Mid(i, 1)

If char >= "A" And char <= "Z" Then
  wordLength = wordLength + 1
Else
  If wordLength >= 1 Then
    count = count + 1
    wordLength = 0
  End If
End If

Next

Return count

takes 6 seconds. just a 75KB file to count the words. seems to long. maybe C language less than 1 second.

A big difference between Xojo and C is that C looks at bytes, not (potentially multi-byte) characters. Try it with MidB() or stuff the string into a MemoryBlock. You should get a lot better speed.

As for your original question, threading introduces a bit of overhead. The tradeoff is process speed vs. keeping the UI responsive. The fact that you found the UI to be sluggish indicates that the thread should be slowed down even further to keep the UI responsive.

good tip,just change mid to midb, the total 75kb file to count the words only taks 0.06 seconds. speed up 100 times.

I considering there must be lots of optimize ideas ,or lots of some knowledges I don’t know in xojo …

I will start it’s example one by one…

thanks tim ~

still a problem:

why this sentence " If char >= “A” And char <= “Z” Then"

not "If char >= “A” And char <= “z” Then "

xojo is case insensitive

you could write that as

If char >= “a” And char <= “Z” Then
If char >= “A” And char <= “Z” Then
If char >= “A” And char <= “z” Then
If char >= “a” And char <= “z” Then

and they would all do the same thing :slight_smile:
Not so in C

thanks

in fact in C to get the same effect you’d have to check A-Z || a-z so you exclude the characters which are in between the uppercase alphabetic & lower case alphabetic in ASCII [ \ ] ^ _ and `

yes,if I want to read the byte of char ,just use chrb()

assuming it IS just one byte :slight_smile: