Closed rosenning closed 9 months 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;
}
你把日志输出看看,确认下,是10s而不是10ms
随机生成10个订单号,就需要5秒,同样的雪花算法,2.5秒生成100W个订单号。我也是按照ReadMe.txt里面写的代码,我很奇怪,为啥有这么大的性能差异。