You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-5Lines changed: 69 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ gxOQRIVR4B_uGHD6OP76XA
35
35
Zo_hpnDxkOsAWLk1tIS6DA
36
36
```
37
37
---
38
-
## Guid is ~10x faster than `github.com/google/uuid`
38
+
## Guid is ~10x faster than `github.com/google/uuid` 🔥
39
39
40
40
*`guid.New()` is 6~10 ns
41
41
*`guid.NewString()` is 40~60 ns
@@ -47,14 +47,78 @@ Zo_hpnDxkOsAWLk1tIS6DA
47
47
| Function | Description |
48
48
|---|---|
49
49
|`guid.New()`| Generate a new Guid |
50
-
|`guid.NewString()`| Generate a new Guid as Base64Url string |
50
+
|`guid.NewString()`| Generate a new Guid as q Base64Url string |
51
51
|`guid.Parse(s)`| Parse Base64Url string to Guid |
52
52
|`guid.ParseBytes(b)`| Parse Base64Url bytes to Guid |
53
53
|`guid.FromBytes(b)`| Parse 16-byte slice to Guid |
54
-
|`guid.Read()` 🔥 | Faster alternative to `crypto/rand`|
54
+
|`guid.Read()` 🔥 | Faster alternative to `crypto/rand`|
55
55
|`guid.Nil`| The zero-value Guid |
56
56
57
-
## Benchmarks
57
+
## Sequential Guids 🔥
58
+
`guid` includes two special types `GuidPG` and `GuidSS` optimized for use as database primary keys (PostgreSQL and SQL Server). Their time-ordered composition helps prevent index fragmentation and improves `INSERT` performance compared to fully random Guids. Note that sequential sorting is only across `time.Now()` timestamp presision.
59
+
60
+
***`guid.NewPG()`**: Generates a `GuidPG`, which is sortable in **PostgreSQL**. It is structured as `[8-byte timestamp][8 random bytes]`.
61
+
***`guid.NewSS()`**: Generates a `GuidSS`, which is sortable in **SQL Server**. It is structured as `[8 random bytes][8-byte SQL Server-ordered timestamp]`.
62
+
*`.Timestamp()` on `GuidPG`/`GuidSS` returns Guid creation time as UTC `time.Time`.
63
+
64
+
Both `GuidPG` and `GuidSS` are nearly as fast as `guid.New()`. They can be used as a standard `Guid` and support the same interfaces.
0 commit comments