51Testing软件测试网
  • 软件测试门户
  • 软件测试培训
  • 文章资料精选
  • 软件测试论坛
  • 测试解决方案
  • 软件测试博客
  • 测试招聘求职

  • 老版网站
  • 加入收藏
  • 关于我们

  • 行业资讯
  • 业务知识
  • 软件测试技术
  • 软件测试工具
  • 软件测试管理
  • 软件开发专栏
  • 软件测试下载
  • 软件测试杂志
  • 软件测试沙龙
您的位置: 首页 >> 文章 >> 测试丛书 >> 互联网单元测试及实践 >> 精选文章

最新更新

51Testing丛书连载:(十三) 互联网单元测试及实践
51Testing丛书连载:(十二) 互联网单元测试及实践
51Testing丛书连载:(十一) 互联网单元测试及实践
51Testing丛书连载:(十) 互联网单元测试及实践
51Testing丛书连载:(九) 互联网单元测试及实践
51Testing丛书连载:(八) 互联网单元测试及实践
51Testing丛书连载:(七) 互联网单元测试及实践
51Testing丛书连载:(六) 互联网单元测试及实践
51Testing丛书连载:(五) 互联网单元测试及实践
51Testing丛书连载:(四) 互联网单元测试及实践

相关阅读

51Testing丛书连载:(十二) QTP自动化测试实践
51Testing丛书连载:(三) 互联网单元测试及实践
51Testing丛书连载:(十一) QTP自动化测试实践
51Testing丛书连载:(十四)性能测试从零开始——LoadRunner入门
51Testing丛书连载:(二) 互联网单元测试及实践
51Testing丛书连载:(十) QTP自动化测试实践
51Testing丛书连载:(十三)性能测试从零开始——LoadRunner入门
51Testing丛书连载:(一) 互联网单元测试及实践
51Testing丛书连载:(九) QTP自动化测试实践
51Testing丛书连载:(十二)性能测试从零开始——LoadRunner入门

51Testing丛书连载:(四) 互联网单元测试及实践

发布时间: 2008-7-15 18:02    作者: 陈卫俊 赵璨 周磊等    来源: 51Testing软件测试网

字体:  小  中  大  | 上一篇 下一篇 | 打印  | 我要投稿  | 每周一问,答贴有奖

5.4.2  方法被调用的次数

        考虑方法的性能时,除了方法本身的执行速度要很快以外,方法本身被其他方法调用的次数也是很重要的。事实上,顶层的方法执行速度稍微慢一点通常问题都不大,而底层的方法其执行速度必须要快,否则就可能导致性能不佳,因为底层方法通常被调用次数比较多,而顶层方法被调用次数一般很少。

        这里其实包含了两点:

        1.可能被大量调用的底层方法,其执行速度必须非常快,这样才能保证整个系统的性能是可接受的。

        2.顶层的方法要注意尽可能地减少调用底层方法的次数,尤其是应当尽可能地避免循环调用底层方法。

        来看看下面的这个例子,这个例子是模拟将一些记录分页进行显示,每页最多显示20条记录,例子中总共1000条记录,显示第11页的记录,跟现实的情况比较接近。这个例子一共包含3个类:RepeatedInvoke、InfoPageDao和PageInfo,代码如下。

代码5.15  RepeatedInvoke类

01 import java.util.Vector;

02 

03 public class RepeatedInvoke {

04 

05  public static void main(String args[]) {

06   try {

07    int pagenum=11;

08    int size;

09    RepeatedInvoke ri=new RepeatedInvoke();

10    Vector currentpage;

11    currentpage=ri.getCurrentPage(pagenum);

12    for(int index=0;index<currentpage.size();index++){

13     System.out.println(((PageInfo)(currentpage.get (index))).        getTitle());

14     System.out.println(((PageInfo)(currentpage.get (index))).        getContent());

15    }

16   } catch (Throwable e) {

17    System.err.println("exception");

18   }

19  }

20  

21  public Vector getCurrentPage(int pagenum) throws Exception {

22   // 每页显示的记录数

23   int countperpage = 20;

24   // 总的记录数

25   int totalSize = getTotalPage().size();

26   // 储存当前页

27   Vector currentpagev = new Vector();

28 

29   if (totalSize % countperpage > 0) {

30    // 总页数

31    int totalpagenum = totalSize / countperpage + 1;

32   }

33 

34 

35 

36   for (int j = 0; j < getTotalPage().size(); j++) {

37    if ((j >= (pagenum - 1) * countperpage)

38      && (j < pagenum * countperpage)) {

39     currentpagev.addElement(getTotalPage().get(j));

40    }

41    // 当currentpagev记录数等于每页显示记录数,

42    // 停止往currentpagev中添加记录

43    if (currentpagev.size() == countperpage) {

44     break;

45    }

46   }

47   return currentpagev;

48  }

49 

50  private Vector getTotalPage() throws Exception {

51   // 从数据库获取所有记录数

52   InfoPageDao dao = new InfoPageDao();

53   return dao.getPageResult("Product.getTolalPage");

54  }

55 }

代码5.16  InfoPageDao类

01 import java.util.Vector;

02 

03 

04 public class InfoPageDao {

05  

06  private static int count = 0;

07 

08  public Vector getPageResult(String string) throws Exception {

09   if(string == "Product.getTolalPage"){

10    Vector v = new Vector();

11    for(int i=0;i<1000;i++){

12     PageInfo info = new PageInfo();

13     info.setTitle(count+"\ttitle");

14     info.setContent(count+"\tcontent");

15     count ++;

16    v.add(info);

17    }

18    count = 0;

19    return v;

20   }

21   else{

22    throw new Exception("unsupport");

23   }

24   

25  }

26 

27 }



TAG: 单元测试 互联网单元测试及实践 测试丛书
31/3123>
软件测试技术

查看全部评论(0)我来说两句

-5 -3 -1 - +1 +3 +5

51Testing软件测试网 | 快捷面板 | 站点地图 | 联系我们 | 广告服务

建议使用IE 5.0以上浏览器,800×600以上分辨率,常年法律顾问:商建刚律师
版权所有 51testing软件测试网 Copyright@51testing.com 2003-2009, 沪ICP备05003035号
意见反馈及技术支持:webmaster@51testing.com 业务联系:service@51testing.com 电话:021-64471599