timetest.java

来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 36 行

JAVA
36
字号
// Introduced in Chapter 7/** Time tests to compare performance of various algorithms. */public class TimeTest {  /** Number of Objects to store in each data structure. */  public static final int LIST_LENGTH = 100;  /** Number of times to perform the operation being timed. */  public static final int TEST_RUNS = 1000000;  /**   * Store LIST_LENGTH Objects in list.  Time list's get() method,   * printing the number of milliseconds taken.   */  public static void test(List<Object> list) {    for (int i = 0; i < LIST_LENGTH; i++) {      list.add(new Object());    }    long before = System.currentTimeMillis();    for (int i = 0; i < TEST_RUNS; i++) {      list.get(5);    }    long after = System.currentTimeMillis();    System.out.println((after - before) + " milliseconds");  }    /** Compare ArrayList with LinkedList. */  public static void main(String[] args) {    System.out.print("ArrayList: ");    test(new ArrayList<Object>());    System.out.print("LinkedList: ");    test(new LinkedList<Object>());  }}

⌨️ 快捷键说明

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