Skip to content

rand: add uuid_v7(), session function, simplify uuid_v4()#24313

Merged
spytheman merged 4 commits into
vlang:masterfrom
kbkpbot:add-rand-uuid_v7
Apr 25, 2025
Merged

rand: add uuid_v7(), session function, simplify uuid_v4()#24313
spytheman merged 4 commits into
vlang:masterfrom
kbkpbot:add-rand-uuid_v7

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Feature request #24311

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-22689

@kbkpbot kbkpbot changed the title rand: add uuid_v7() rand: add uuid_v7(), session function, simplify uuid_v4() Apr 25, 2025

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.
What is the performance of the new uuid_v4 implementation compared to the old one?

@kbkpbot

kbkpbot commented Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

Good work. What is the performance of the new uuid_v4 implementation compared to the old one?

A simple benchmark:

module main
import rand
import benchmark

fn main() {
        mut b := benchmark.start()

        for _ in 0..10000000 {
                rand.uuid_v4()
        }
        b.measure('uuid_v4')
}

old version:

$ ./r
 SPENT  3146.729 ms in uuid_v4

new version:

$ ./r
 SPENT   925.424 ms in uuid_v4

This is mainly because old version uuid_v4() generate a single uuid will use 4 calls of rand.u64() , but the new version only use 2 calls of rand.u64().

@spytheman spytheman merged commit e0a7f87 into vlang:master Apr 25, 2025
@JalonSolov

Copy link
Copy Markdown
Collaborator

Ooo... gotta love it. Add feature AND increase performance at the same time? Nice...

@kbkpbot kbkpbot deleted the add-rand-uuid_v7 branch April 25, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants