text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int count = 10000;
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
String code = (Math.random() + "").substring(2, 8);
if (code.length() != 6) {
System.out.println("生成失败:" + code);
}
}
long end = System.currentTimeMillis();
System.out.println("截取耗时:" + (end - start));
System.out.println("===================================================");
start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
String code = String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, 5)));
if (code.length() != 6) {
System.out.println("生成失败:" + code);
}
}
end = System.currentTimeMillis();
System.out.println("整数运算,执行时间:" + (end - start));
耗时:





评论
登录后即可评论
分享你的想法,与作者互动
暂无评论