yitter / IdGenerator

💎多语言实现,高性能生成唯一数字ID。 💎优化的雪花算法(SnowFlake)——雪花漂移算法,在缩短ID长度的同时,具备极高瞬时并发处理能力(50W/0.1s)。 💎原生支持 C#/Java/Go/Rust/C/JavaScript/TypeScript/Python/Pascal 多语言,提供其它适用于其它语言的多线程安全调用动态库(FFI)。💎支持容器环境自动扩容(自动注册 WorkerId ),单机或分布式唯一IdGenerator。💎顶尖优化,超强效能。
MIT License
2.51k stars 363 forks source link

单线程性能很慢 #69

Closed rosenning closed 9 months ago

rosenning commented 1 year ago

随机生成10个订单号,就需要5秒,同样的雪花算法,2.5秒生成100W个订单号。我也是按照ReadMe.txt里面写的代码,我很奇怪,为啥有这么大的性能差异。

rosenning commented 1 year ago

long start = System.currentTimeMillis(); for(int i=0;i<10;i++) { getOrderNum(); } long end = System.currentTimeMillis(); System.out.println("完成工作,耗时"+ (end-start)+"ms"); orderList.forEach((e)->System.out.println(e));

private static void getOrderNum() { long newId = getHelper().nextId(); //orderList.add(newId); //System.out.println(newId); }

private static YitIdHelper helper = null;

private static YitIdHelper getHelper() {
    if(helper == null) {
        IdGeneratorOptions options = new IdGeneratorOptions();
        options.SeqBitLength = 10;
        helper.setIdGenerator(options);
    }
    return helper;
}
yitter commented 1 year ago

你把日志输出看看,确认下,是10s而不是10ms