⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excperf.java

📁 PracticalJAVACode 的源码
💻 JAVA
字号:
class ExcPerf
{
  public void method1(int size)                               
  {
    int[] ia = new int[size];
    try {
      for (int i=0; i<size; i++)
        ia[i] = i;
      //...
    }
    catch (Exception e){}
  }

  public void method2(int size)                               
  {
    int[] ia = new int[size];
    for (int i=0; i<size; i++)
    {
      try {                                                   
          ia[i] = i;
          //...
      }
      catch (Exception e){}
    }
  }

  public static void main(String args[])
  {
    int size = Integer.parseInt(args[0]);
    ExcPerf ep = new ExcPerf();
    long start = System.currentTimeMillis();
    ep.method1(size);
    long end = System.currentTimeMillis();
    System.out.println("normal processing took an average of " +
      (end-start) + " milliseconds");

    start = System.currentTimeMillis();
    ep.method2(size);
    end = System.currentTimeMillis();
    System.out.println("try/catch block processing took an " +
                  "average of " + (end-start) + " milliseconds");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -