You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.v 617 B

4 years ago
12345678910111213141516171819202122232425262728293031
  1. module main
  2. import time
  3. import contract
  4. import gen
  5. fn main(){
  6. // 方法一:直接采用默认方法生成一个Id
  7. yid := gen.YitIdHelper{
  8. id_gen: gen.make_generator(&contract.IdGeneratorOptions{
  9. method: 1
  10. base_time: 1582136402000
  11. workerid_bitlength:6
  12. seq_bitlength:6
  13. })
  14. }
  15. println(yid.next_id())
  16. // 方法二:自定义参数
  17. times := 50000
  18. for {
  19. begin := time.now().unix_time_milli()
  20. for i := 0; i < times; i++ {
  21. yid.next_id()
  22. }
  23. end := time.now().unix_time_milli()
  24. println("漂移,总共:"+times.str()+","+(end-begin).str()+" ms")
  25. time.sleep(1 * time.second)
  26. }
  27. }

雪花算法中非常好用的数字ID生成器