@@ -30,19 +30,18 @@ Turbo mode:
3030
3131.. code-block :: python
3232
33- from datetime import datetime, timezone
34- from random import sample
33+ from time import time_ns
3534 from timeit import timeit
3635
37- from sonyflake_turbo import SONYFLAKE_MACHINE_ID_MAX , MachineIDLCG, SonyFlake
36+ from sonyflake_turbo import MachineIDLCG, SonyFlake
3837
39- get_machine_id = MachineIDLCG(int (datetime.now( tz = timezone.utc).timestamp() ))
40- epoch = datetime( 2025 , 6 , 5 , tzinfo = timezone.utc)
38+ get_machine_id = MachineIDLCG(time_ns( ))
39+ EPOCH = 1749081600 # 2025-06-05T00:00:00Z
4140
4241 for count in [32 , 16 , 8 , 4 , 2 , 1 ]:
43- machine_ids = sample( range ( SONYFLAKE_MACHINE_ID_MAX + 1 ), count)
44- sf = SonyFlake(* machine_ids, start_time = int (epoch.timestamp()) )
45- t = timeit(lambda : [ next (sf) for _ in range (1000 )] , number = 1000 )
42+ machine_ids = [get_machine_id() for _ in range ( count)]
43+ sf = SonyFlake(* machine_ids, start_time = EPOCH )
44+ t = timeit(lambda : sf (1000 ), number = 1000 )
4645 print (f " Speed: 1M ids / { t:.2f } sec with { count} machine IDs " )
4746
4847 Async:
0 commit comments