list of 10000 points randomly spread over a 1000000 x 1000000 grid
The results the list search returned times of around 50msec
I did the same thing using X and Y Arrays rather than List, and I'm getting search speeds of 78 million points per second = 7800 searches of 10000 points per second = 0.128 ms per search (ie 0.000128 seconds).
cf your timings... I know I'm good, but I also know I'm not *that* good. ?
edit: was done with B4J on laptop rather than B4A on phone, but... is hard to believe the (almost) 400x speed differential between the two
You mentioned 1 million x 1 million grid, so I used 32 bit Ints for coordinates, and 64 bit Longs to do the math. Did you do same, or use floating point?
Also, I did squaring using * rather than ^
edit: Also, I searched for random points rather than repeatedly for the centre.
edit: Also, there are some Logs included within the timed section, because I was having trouble believing the times I was getting
Done using B4J on elcheapo Windows laptop bought new maybe six months ago for < $400 (ie < 250 USD ?)
Sub AppStart (Args() As String)
Log("Hello world!!!")
Dim NumPoints As Int = 10000
Dim X(NumPoints) As Int
Dim Y(NumPoints) As Int
For I = 0 To NumPoints - 1
X(I) = Rnd(-500000, 500000)
Y(I) = Rnd(-500000, 500000)
Next
Log(DateTime.Now)
Dim StartTime As Long = DateTime.Now
Dim NumBurls As Int = 1000
Dim NumCalcs As Int = 0
For Burl = 1 To NumBurls
Dim FindX As Long = Rnd(-510000, 510000)
Dim FindY As Long = Rnd(-510000, 510000)
Dim ClosestI As Int
Dim ClosestDistanceSquared As Long
For I = 0 To NumPoints - 1
Dim DX As Long = FindX - X(I)
Dim DY As Long = FindY - Y(I)
Dim DistanceSquared As Long = DX * DX + DY * DY
If I = 0 Then
ClosestI = I
ClosestDistanceSquared = DistanceSquared
else If DistanceSquared < ClosestDistanceSquared Then
ClosestI = I
ClosestDistanceSquared = DistanceSquared
End If
NumCalcs = NumCalcs + 1
Next
'''Log(Burl & tab & FindX & TAB & FindY & TAB & ClosestI & TAB & ClosestDistanceSquared)
If Burl Mod 100 = 0 Then Log(Burl & TAB & (DateTime.Now - StartTime))
Next
Dim EndTime As Long = DateTime.Now
Log(DateTime.Now)
Log(((EndTime - StartTime) / NumBurls) & TAB & NumCalcs & TAB & ClosestI & TAB & ClosestDistanceSquared)
Log(NumberFormat(NumCalcs / ((EndTime - StartTime) / 1000), 1, 0))
End Sub
Waiting for debugger to connect...
Program started.
Hello world!!!
1698295569995
100 23
200 78
300 84
400 92
500 97
600 105
700 111
800 117
900 123
1000 128
1698295570123
0.128 10000000 6292 1142480
78,125,000
Program terminated (StartMessageLoop was not called).