@@ -23,26 +23,29 @@ Easy mode:
2323
2424 sf = SonyFlake(0x 1337 , 0x CAFE , start_time = 1749081600 )
2525
26- for _, id_ in zip (range (10 ), sf):
27- print (f " { id_:016x } " )
26+ print (" one" , next (sf))
27+ print (" n" , sf(5 ))
28+
29+ for id_ in sf:
30+ print (" iter" , id_)
31+ break
2832
2933 Turbo mode:
3034
3135.. code-block :: python
3236
33- from datetime import datetime, timezone
34- from random import sample
37+ from time import time_ns
3538 from timeit import timeit
3639
37- from sonyflake_turbo import SONYFLAKE_MACHINE_ID_MAX , MachineIDLCG, SonyFlake
40+ from sonyflake_turbo import MachineIDLCG, SonyFlake
3841
39- get_machine_id = MachineIDLCG(int (datetime.now( tz = timezone.utc).timestamp() ))
40- epoch = datetime( 2025 , 6 , 5 , tzinfo = timezone.utc)
42+ get_machine_id = MachineIDLCG(time_ns( ))
43+ EPOCH = 1749081600 # 2025-06-05T00:00:00Z
4144
4245 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 )
46+ machine_ids = [get_machine_id() for _ in range ( count)]
47+ sf = SonyFlake(* machine_ids, start_time = EPOCH )
48+ t = timeit(lambda : sf (1000 ), number = 1000 )
4649 print (f " Speed: 1M ids / { t:.2f } sec with { count} machine IDs " )
4750
4851 Async:
@@ -55,11 +58,11 @@ Async:
5558 sf = SonyFlake(0x 1337 , 0x CAFE , start_time = 1749081600 )
5659 asf = AsyncSonyFlake(sf, sleep)
5760
58- print (await asf)
59- print (await asf(5 ))
61+ print (" one " , await asf)
62+ print (" n " , await asf(5 ))
6063
6164 async for id_ in asf:
62- print (id_)
65+ print (" aiter " , id_)
6366 break
6467
6568 Important Notes
0 commit comments