@Kem_Tekinay and I spent a ton of time benchmarking and building out different methods. We included in our testing the method I built that can be found here which generates a UUIDv7 (while most if not all others generate UUIDv4). Together we worked up a very quick alternative native implementation, but I don’t recall what happened with that.
and btw, the MBS lite requires a database a x-desktop license to build, altough lite version normally deals with sqlite dbs, explained my misundersting about licenes these days, sorry for the noise
There is another way to generate an UUID via OS declare which is missing in your sample code.
Public Function uuid_generate() As String
#Pragma BackgroundTasks false
#Pragma StackOverflowChecking False
Declare Sub uuid_generate Lib "foundation" (buf As Ptr)
Var buf As New MemoryBlock(16)
Dim out() As String
uuid_generate(buf)
Dim b As Byte
For i As Integer = 0 To buf.Size-1
b = buf.Byte(i)
out.Add if(b > 15, b.ToHex, "0" + b.ToHex)
Next
Return String.FromArray(out, "")
End Function
On my M1 MacBook it takes about 160 ms to generate 200 000 UIDs in debug mode. How long does it take on your Mac Mini M4 in a build application (no debug mode)?
It works when formatting correctly.
There are too many pipes | on some line and the second line wasn’t formatted properly as it seems there are three columns
Hm… i wonder why it is so slow for you. The MacMini M4 should be faster than my old M1 MacBook…
I used your project cleaned from plugin code since I don’t use any plugin.
So with the optimized code it takes about 82 ms (in debug mode!) with following code in Button5.pressed:
#Pragma BackgroundTasks false
#Pragma StackOverflowChecking False
Declare Sub uuid_generate Lib "foundation" (buf As Ptr)
var j As Integer
Var wuuid as String
Var startTime As DateTime = DateTime.Now
Var buf As New MemoryBlock(16)
Dim b As Byte
for j = 1 to 200000
uuid_generate(buf)
Dim out() As String
For i As Integer = 0 To buf.Size-1
b = buf.Byte(i)
out.Add if(b > 15, b.ToHex, "0" + b.ToHex)
Next
wuuid = String.FromArray(out, "")
Next
TextField1.text = wuuid
Var EndTime As DateTime = DateTime.Now
Var d As DateInterval = EndTime - startTime
Var duration As Double = d.Nanoseconds / 1000000
TextField2.AddText "Duration: " + duration.ToString + " ms" +EndOfLine
Funny, using your project I get 178 ms (all other functions are commented because there are MBS calls). Running my project is still somehow 10 % faster.
Did you use a debug run or an application build for testing? The latter should be faster.
Well, even the subject tells it is a useless benchmark.
It is just fun to optimize code to get it as fast as possible. Even more when there is no need to use a plugin when a simple declare works well.