Uuids generating useless benchmark

since there is now 4 ways to generate uuids and xojo introduced one in latest release, i make a simple file to test creating 200 000 uuids

results ms
on mac mini M4

M _UUID 2212

Einhugur 60

MBS Sqlite 721

Xojo system 869

–on linux

M _UUID 26733

Einhugur 232

MBS Sqlite 3639

Xojo system 1644

file here
uuid.zip (9.5 KB)

1 Like
Method Mac Mini M4 (ms) Linux (ms)
M_UUID 2212 26733
Einhugur 60 232
MBS Sqlite 721 3639
Xojo system 869 1644
3 Likes

thanks how did you do that ! :slight_smile:

By using Markdown:

| Method             | Mac Mini M4 (ms) | Linux (ms) |
| :----------------- | ---------------: | ---------: |
| M_UUID             | 2212             | 26733      |
| Einhugur           | 60               | 232        |
| MBS Sqlite         | 721              | 3639       |
| Xojo system        | 869              | 1644       |
2 Likes

@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.

Edit: Oh, what we worked on together is M_UUID. :smiley:

yes Einhugur one generates v7 too, while xojo system generates v4, and is all caps ?

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)?

1 Like

If you use SQLConnectionMBS you should not require a Desktop license from Xojo, i think.

1 Like

yes that what i thought too stubornely ! maybe it’s a mistake from compiler @Christian_Schmitz ?

compiled app on mac mini M4

| Method | Mac Mini M4 (ms) |
| :----------------- | ---------------: | --------``-: |
| M_UUID | 1796 |
| Einhugur | 38 ||
| MBS Sqlite | NA | |
| Xojo system | 869 | |
| Declare Tom | 424 | |

file without MBS
uuiddeclare.zip (7.5 KB)

sorry , how do you declare it’s markdown to editor ?

Method Mac Mini M4 (ms)
M_UUID 1796
Einhugur 38
MBS Sqlite NA
Xojo system 869
Declare Tom 424

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

2 Likes

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
1 Like

!!! how 's that ? i had bunch of apps loaded, i rebooted
i have


funny timeMBS doest tave same result !
but i still have higher result ??!!
new version with button with no dependencies

uuid3.zip (7.4 KB)

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.

???!! ??? i’m about to reformat my drive lowlevel lol

1 Like

First the benchmark is quite useless. Generating UUIDs is hardly ever the bottleneck in your code.

SQLConnectionMBS class can be used in Xojo Lite. Just don’t touch SQLDatabaseMBS, RecordSet, RowSet, DatabaseRow and other Xojo database classes.

Why do you go through SQLite and not use our UUIDMBS, NSUUIDMBS or CFUUIDMBS classes?

This is simultaneously the most pedantic and the most interesting thing I’ve seen all day. :laughing: Thanks for sharing!

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.