首页 > 其他 > 详细

try catch 效率

时间:2014-02-25 22:31:41      阅读:302      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
}
long end = System.currentTimeMillis();
System.out.println("---:"+(end-start));
long start1 = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
    try {
    } catch (Exception e) {
    }
}
long end1 = System.currentTimeMillis();
System.out.println("---:"+(end1-start1));
long start2 = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
    try {
        throw new Exception();
    } catch (Exception e) {
    }
}
long end2 = System.currentTimeMillis();
System.out.println("---:"+(end2-start2));

---:1
---:1
---:795

try catch只要不抛异常就对效率影响不大。

-------------------------------------------------------------

在第一个循环里加入system.out.print("");其余两个循环try catch里也加入system.out.print("");

---:136
---:130
---:920

 

堆栈跟踪

try catch 效率

原文:http://www.cnblogs.com/keia/p/3566443.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!