We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LIFE GAME : How to optimise/speed up ?
#1
Hello, it's me again Smile

I try to improve my level, so I began another SB project : a life game (NVCV425.000)
I would like to know how to make it run faster, as with big grids it becomes very slow.


For exemple, is there a faster way to display the living cells than using GraphicsWindow.FillRectangle ?


My only idea at this moment to make it a little faster is to merge these 2 Subs (because they can be done in the same loop) :
Sub AffichageTableau               ' displays current Gen grid
Sub CreationTableau_NextGen  '  create nextGen grid

If you have any idea...  Wink
Reply
#2
Use LDFastshapes
ZS
Reply
#3
Hi again,

The main reason is that Small Basic arrays are slow and 2D array can be very slow - this was an internal design decision that arises from SB having no types (int, float string etc).

Not so much you can do about it unless you use an extension as ZS suggests.  I have no idea if you do or not, or want to consider this.

Anyway I did a little test to show:

Code:
size = 100
T1 = Clock.ElapsedMilliseconds
For x = 1 To size
  For y = 1 To size
    rand = Math.GetRandomNumber(100)
    If 50 > rand Then
      table1[x][y] = 1
    Else
      table1[x][y] = 0
    EndIf
  EndFor
EndFor
T2 = Clock.ElapsedMilliseconds
For x = 1 To size
  For y = 1 To size
    If table1[x][y] = 1 Then
      table2[x][y]= 0
    Else
      table2[x][y]= 1
    EndIf
  EndFor
EndFor
T3 = Clock.ElapsedMilliseconds
TextWindow.WriteLine(T2-T1)
TextWindow.WriteLine(T3-T2)

On my PC (which is quite high spec) I get times of around 150 ms for each of the 2 passes.

If I code the same using a LitDev extension method LDFastArray as below, I get timings of around 8 ms for each (this is actually still not very fast due to overheads using function calls and underlying SB data types, but better).

Code:
T1 = Clock.ElapsedMilliseconds
arr1 = LDFastArray.Add()
For x = 1 To size
  For y = 1 To size
    rand = Math.GetRandomNumber(100)
    If 50 > rand Then
      LDFastArray.Set2D(arr1,x,y,1)
    Else
      LDFastArray.Set2D(arr1,x,y,0)
    EndIf
  EndFor
EndFor
T2 = Clock.ElapsedMilliseconds
arr2 = LDFastArray.Add()
For x = 1 To size
  For y = 1 To size
    If LDFastArray.Get2D(arr1,x,y) = 1 Then
      LDFastArray.Set2D(arr2,x,y,0)
    Else
      LDFastArray.Set2D(arr2,x,y,1)
    EndIf
  EndFor
EndFor
T3 = Clock.ElapsedMilliseconds
TextWindow.WriteLine(T2-T1)
TextWindow.WriteLine(T3-T2)

There are other faster array tpes LDList (for 1D arrays not indexed by integer with improved sort capabilities) or LDArray (fastest for 1D arrays with a pre-defined size).

If you are interested in these instruction for using LitDev extension can be found at https://litdev.uk and we can help futher with this.  As ZS says there may be other optimisations, but I expect the arrays are the main offenders here.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#4
Hello,
Thank you for your Answers.
I installed SB-Prime (an advice from AB) and installed LitDed from the advanced menu.
When clicking on RUN SB tels me that it is impossible beacause of a virus or malware  Sick


see on this link : https://e.pcloud.link/publink/show?code=...hOk5nAJBy7
Reply
#5
Yeh, I know I get that too.  I don't know what specifically it is, but there is loads of stuff in the LitDev.dll including for example the networking server stuff AB is using or other things that generic antivirus probably don't like.

I can say it is safe if you download directly from my site (e.g. using SB-Prime from my site) and the code is open source on GitHub.

What I do is using Windows Security->Virus & threat protection->Exclusions, then add an exclusion for the folder where I store all SmallBasic files (A sub folder of Documents).  I then save any SB file I want to run, if I download the file I check it first, uncomment File commands as necessary, being sure about what it is doing.  Some-one could write a program to delete stuff!

I don't run Small Basic programs without saving first - if you don't save then they run in %temp%, over time clogging it up as SB doesn't clean up after itself.  Also I wouldn't put an anti-virus exclusion for %temp% folder.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#6
But I have seen in temp folder the program are of zero kb sized.
Elzaimer you could also use extension manager in SB Prime or manual download extension manager from https://litdev.uk maybe it could work.
ZS
Reply
#7
https://www.virustotal.com is a good place to test a dll for false positive virus, there are probably other similar sites.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)