public static void main(String[] args) {

    try {
      // Create the table
      DbDAO.createTable();

      // Save 1000 names with nonprepared statements
      double nonPreparedSave;
      StopWatch sw = new StopWatch();
      for (int i = 0; i < 1000; i++) saveNameNonPrepared("person" + i);
      nonPreparedSave = sw.elapsedTime();

      // Reset the table
      dropTable();
      DbDAO.createTable();

      // Save 1000 names with prepared statements
      double preparedSave;
      ArrayList<String> names = new ArrayList<String>();
      for (int i = 0; i < 1000; i++) names.add("person" + i);
      sw = new StopWatch();
      saveNamePrepared(names);
      preparedSave = sw.elapsedTime();

      // Print af test af 1000 saves
      System.out.println(
          "1000 names saved! \nNonprepared: " + nonPreparedSave + "\nPrepared: " + preparedSave);

      // Load 1000 names nonprepared ( We use that the table consists of the 1000 names from the
      // arraylist names)
      double nonPreparedLoad;
      sw = new StopWatch();
      for (String s : names) loadNameNonPrepared(s);
      nonPreparedLoad = sw.elapsedTime();

      // Load 1000 names prepared ( We use the arraylist names again )
      double preparedLoad;
      sw = new StopWatch();
      loadNamesPrepared(names);
      preparedLoad = sw.elapsedTime();

      // Print af test af 1000 saves
      System.out.println(
          "1000 names loaded! \nNonprepared: " + nonPreparedLoad + "\nPrepared: " + preparedLoad);

      // Reset table again
      dropTable();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    int N = 10000000;
    int K = 1;
    Integer[] newArray = new Integer[N];
    StopWatch sw = new StopWatch();
    while (K <= N) {
      newArray = createArray(N, K);
      Sorting obj = new Sorting(newArray);
      newArray = (Integer[]) obj.selectionsort();

      System.out.println("The time needed for K=" + K + " is " + sw.elapsedTime());
      K = K * 2;
      System.out.println(
          "The number of comparisons is "
              + obj.compareCount()
              + "; "
              + "The number of exchanges is "
              + obj.exchangeCount()
              + "; "
              + "The number of copies is "
              + obj.copyCount()
              + "; ");
    }
  }