I have a web-based Java application that generates random UUIDs for session information. One of our testers is claiming up to 350ms to generate UUIDs based upon his own profiling, but I have not yet been able to replicate his results. He points to this article to help back up his results.
Results about 2 microseconds per UUID.
Results about 20 microseconds per UUID.
Testing a custom implementation of UUID generation using regular java.util.Random
shows similar speeds to the built-in UUID.randomUUID()
method.
The UUID.randomUUID()
method uses SecureRandom
internally, which is designed for high-quality entropy. The custom implementation using java.util.Random
has the potential to be more predictable and collide more often.
The performance of UUID.randomUUID()
appears to be influenced by the operating system and the specific configuration of the system. The built-in method is generally faster and more secure.