Skip to content

Conversation

@ryanwinchester
Copy link

@ryanwinchester ryanwinchester commented Oct 13, 2020

Add UUID v6 (RFC draft) function.

Related web page: http://gh.peabody.io/uuidv6/

I tried to follow the existing code style and conventions as much as possible.

Example reference

For reference (to see how similar a v1 is to a v6), here is a python example from the RFC author converting a UUID v1 to a UUID v6:

import uuid

def uuidv1tov6(u):
  uh = u.hex
  tlo1 = uh[:5]
  tlo2 = uh[5:8]
  tmid = uh[8:12]
  thig = uh[13:16]
  rest = uh[16:]
  uh6 = thig + tmid + tlo1 + '6' + tlo2 + rest
  return uuid.UUID(hex=uh6)

u = uuidv1tov6(uuid.uuid1())

Benchmarks

▶ mix bench
Settings:
  duration:      1.0 s

## UUIDBench
[17:17:54] 1/9: binary_to_string!
[17:18:04] 2/9: info!
[17:18:06] 3/9: string_to_binary!
[17:18:09] 4/9: uuid1
[17:18:11] 5/9: uuid3 dns
[17:18:13] 6/9: uuid4
[17:18:16] 7/9: uuid5 dns
[17:18:17] 8/9: uuid6 mac_address
[17:18:20] 9/9: uuid6 random_bytes

Finished in 27.79 seconds

## UUIDBench
benchmark name      iterations   average time
binary_to_string!     10000000   0.84 µs/op
uuid3 dns              1000000   1.45 µs/op
uuid5 dns              1000000   1.54 µs/op
uuid4                  1000000   2.39 µs/op
string_to_binary!      1000000   3.12 µs/op
info!                   500000   3.13 µs/op
uuid6 random_bytes      500000   4.19 µs/op
uuid6 mac_address        10000   208.53 µs/op
uuid1                    10000   209.47 µs/op

Closes #44

@ryanwinchester ryanwinchester force-pushed the master branch 3 times, most recently from 188c02d to af154d6 Compare October 13, 2020 23:37
Use uuid identifiers module attributes in uuid6/1

Build the UUID v6 instead of converting a v1

Add uuid1<->uuid6 conversion functions

Add some more validations to tests
@ryanwinchester
Copy link
Author

Added benchmarks

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.

V6 UUID

2 participants