Bench2.java

/*
 * $Id: Bench2.java,v 1.27 2008/07/16 08:00:37 koga Exp $
 *
 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
 */
package org.mklab.tool.control.util;

import java.io.IOException;

import org.mklab.nfc.matrix.DoubleComplexMatrix;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.matx.MatxList;
import org.mklab.nfc.ode.SolverStopException;
import org.mklab.nfc.scalar.DoubleComplexNumber;
import org.mklab.nfc.util.ElapsedTimer;
import org.mklab.nfc.util.Pause;


/**
 * ベンチマークを行うクラス
 * 
 * @author koga
 * @version $Revision: 1.27 $
 */
public class Bench2 extends Bench {

  /**
   * @param args コマンドライン引数
   * @throws IOException キーボードから入力できない場合
   * @throws SolverStopException ソルバーが停止された場合
   * @see org.mklab.tool.control.util.Bench#main(java.lang.String[])
   */
  public static void main(String[] args) throws IOException, SolverStopException {
    new Bench2().run();
  }

  /**
   * @throws IOException キーボードから入力できない場合
   * @see org.mklab.tool.control.util.Bench#run()
   */
  @Override
  public void run() throws IOException, SolverStopException {
    System.out.println("**************************************************************"); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.1")); //$NON-NLS-1$
    System.out.println("*                                                            *"); //$NON-NLS-1$
    System.out.println("*  matx-info@matx.org                                        *"); //$NON-NLS-1$
    System.out.println("*                                                            *"); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.5")); //$NON-NLS-1$
    System.out.println("**************************************************************"); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.7")); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.9")); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.10")); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.11")); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.12")); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.13")); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.14")); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.15")); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    Pause.pause();
    DoubleMatrix ts = new DoubleMatrix(1, 7);

    // ベンチマーク結果のヘッダーを表示
    System.out.println(""); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.16")); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$
    System.out.println(Messages.getString("Bench2.17")); //$NON-NLS-1$
    System.out.println(""); //$NON-NLS-1$

    // BenchTimer timer = new BenchTimer();
    ElapsedTimer timer = new ElapsedTimer();

    // 500 by 500 実行列乗算
    DoubleMatrix a = DoubleMatrix.uniformRandom(500);
    timer.start();
    a.multiply(a);
    ts.setElement(1, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(1))); //$NON-NLS-1$

    // N = 500 実行列の逆行列
    a = DoubleMatrix.uniformRandom(500);
    timer.start();
    a.inverse();
    ts.setElement(2, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(2))); //$NON-NLS-1$

    // N = 350 実行列の固有値
    a = DoubleMatrix.uniformRandom(350);
    timer.start();
    a.eigenValue();
    ts.setElement(3, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(3))); //$NON-NLS-1$

    // 2^19 点の複素 FFT
    DoubleComplexMatrix ac;
    ac = DoubleComplexMatrix.uniformRandom(1, (int)Math.pow(2, 19)).add(DoubleComplexMatrix.ones(1, (int)Math.pow(2, 19)).multiply(new DoubleComplexNumber(0, 1)));
    timer.start();
    ac.fft();
    ts.setElement(4, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(4))); //$NON-NLS-1$

    // 2000000 FOR ループ
    a = new DoubleMatrix(1, 2000000);
    timer.start();
    for (int i = 1; i <= 2000000; i++) {
      a.setElement(i, 1);
    }
    ts.setElement(5, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(5))); //$NON-NLS-1$

    // ode 10[s]
    timer.start();
    ode(10);
    ts.setElement(6, timer.getElapsedTime());
    System.out.print("   " + format(ts.getDoubleElement(6))); //$NON-NLS-1$

    // merit
    double merit = (this.js5.divideElementWise(ts.getSubVector(1, 6)).powerElementWise(1.0 / 6)).product().doubleValue();
    ts.setElement(7, merit);
    System.out.print("   " + format(ts.getDoubleElement(7))); //$NON-NLS-1$

    /*
     * System.out.println(""); System.out.println(""); System.out.println("");
     * System.out.println(""); System.out.println("
     * **************************************************************");
     * System.out.println(" * あたなた計算機(機種、OS、コンパイラ)のベンチマーク結果を *");
     * System.out.println(" * *"); System.out.println(" * matx-info@matx.org
     * *"); System.out.println(" * *"); System.out.println(" *
     * まで連絡して下さい。ベンチマークの比較表に追加します。 *"); System.out.println("
     * **************************************************************");
     * System.out.println(""); System.out.println("");
     */

    Pause.pause();

    MatxList yours = new MatxList(new Object[] {Messages.getString("Bench2.18"), Messages.getString("Bench2.19"), ts}); //$NON-NLS-1$ //$NON-NLS-2$

    printBenchTable(this.data, yours);

    int number = this.data.size();

    for (int i = 0; i < number / 7; i++) {
      if (i == number / 7 - 1) {
        System.out.println(Messages.getString("Bench2.20")); //$NON-NLS-1$
        System.out.println(""); //$NON-NLS-1$
      } else {
        System.out.println(Messages.getString("Bench2.21")); //$NON-NLS-1$
        System.out.println(""); //$NON-NLS-1$
      }
      printResult(this.data, 1 + i * 7, (i + 1) * 7, yours);
      System.out.println(""); //$NON-NLS-1$
      Pause.pause();
    }

  }

}