zoukankan      html  css  js  c++  java
  • 测试一下Java代码的执行时间

    今天下午发现菜单读取很慢,调整代码后,想准确的测试一下Java代码的执行时间,搜搜如下:

    ==========方式1
    public void testMenu1_M1() {
    		// --第一种是以毫秒为单位计算的。
    		long startTime=System.currentTimeMillis(); //获取开始时间		
    		Role r = new Role();
    		r.setId(Long.valueOf("2"));
    		List<Module> ls = this.roleService.getModulesByRole_V1(r);		
    		long endTime=System.currentTimeMillis(); //获取结束时间
    	
    		System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
    		System.out.println("1时间: "+startTime+"ms");
    		System.out.println("2时间: "+endTime+"ms");
    		// this.setComplete();
    	}
    	public void testMenu2_M1() {
    		//第二种是以纳秒为单位计算的。
    		long startTime=System.nanoTime(); //获取开始时间		
    		Role r = new Role();
    		r.setId(Long.valueOf("2"));
    		List<Module> ls = this.roleService.getModulesByRole(r);		
    		long endTime=System.nanoTime(); //获取结束时间
    	
    		System.out.println("程序运行时间: "+(endTime-startTime)+"ns");
    		System.out.println("1时间: "+startTime+"ns");
    		System.out.println("2时间: "+endTime+"ns");
    		// this.setComplete();
    	}
    
    =============方式2 用Firefox 插件 Firebug
    也可以得到时间(毫秒)
    
  • 相关阅读:
    Python爬虫学习01
    Python学习Day02
    JavaScript学习笔记01
    Python学习Day01
    MarkDown实例代码
    MarkDwon的使用方法
    (转)探究requestDisallowInterceptTouchEvent失效的原因
    JNI字符串转字节数组指针方法
    justfun
    dsad
  • 原文地址:https://www.cnblogs.com/zhima/p/7474879.html
Copyright © 2011-2022 走看看