I need to generate around a few hundreds of UUIDs and then I need to reuse each UUID a few thousands times.
What will give me better performance?
Option 1: Generate the uuid every time from the input? Option 2: Use Python's lru_cache(maxsize=None) around the method generating the uuid? Option 3: Store the uuid in a dictionary and retrieve it (primitive cache)?
Running 1,000,000 iterations for each option, resulted in these times:
WITHOUT CACHE: 1.53233003616333
WITH CACHE: 0.06612777709960938
WITH DICT: 0.051396846771240234
So, the fastest option is using a dict, but using lru_cache will be milliseconds behind it.
and this surprisingly doesn't do worse. In this example I ran 1000 times for each of 1000 uuids
Running 1,000,000 iterations resulted in these times
WITHOUT CACHE: 1.550447940826416
WITH CACHE: 0.06554079055786133
WITH DICT: 0.051934003829956055