markusthoemmes commented on issue #3396: Self-generate random strings without 
going through a UUID.
URL: 
https://github.com/apache/incubator-openwhisk/pull/3396#issuecomment-373315588
 
 
   Based on a discussion with @rabbah I benchmarked the code (and vastly 
improved it). Here are some numbers:
   
   ```scala
   object Bench {
     def test(name: String, count: Int, generator: => String) = {
       println(s"running $name")
       val start = System.currentTimeMillis()
       Seq.fill(count)(generator)
       println(s"took ${System.currentTimeMillis() - start}")
     }
   
     def main(args: Array[String]): Unit = {
       val secure = new scala.util.Random(new SecureRandom())
   
       println("warmup")
   
       test("uuids", 10000, UUIDs.randomUUID().toString.filterNot(_ == '-'))
       test("randomHex", 10000, RandomString.generateHexadecimal(32))
   
       test("uuids", 10000000, UUIDs.randomUUID().toString.filterNot(_ == '-'))
       test("randomHex", 10000000, RandomString.generateHexadecimal(32))
     }
   }
   ```
   
   ```
   warmup
   running uuids
   took 142
   running randomHex
   took 181
   running uuids
   took 41861
   running randomHex
   took 31486
   ```
   
   You can see that the `randomHex` code is indeed faster now. This is more 
about that code not allocating as much garbage though.
   
   @rabbah WDYT? I'm a bit unsure if this is even worth it 😁.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to