// Stand: 07.11.2010

import java.awt.event.*;
import javax.swing.*;

import java.io.*;

import java.awt.BorderLayout;

// Beispiel zum Testen der modulo Funktion
// Parallele Programmierung

public class Timer3  {


   int Max = 100000000;

   // Konstruktor
  public Timer3 () {
    Test1();
    Test2();
    Test3();
    Test4();
    Test5();
  }


     // init und Start des Timers animator
    public void Test1() {
      long t1, t2;
      double s = 0.0;
       t1 =  System.currentTimeMillis();
        for (int k=0; k<Max; k++) {
          if ( (k % 2) == 0)
            s += 1.0;
          else
            s -= 1.0;
        } // for

       t2 =  System.currentTimeMillis();
       System.out.println( "Modulo: "+(t2-t1) );
    }  // Test1


     // init und Start  Vorz=-Vorz
    public void Test2() {
      long t1, t2;
      double s = 0.0;
      double Vorz = 1.0;
       t1 =  System.currentTimeMillis();
        for (int k=0; k<Max; k++) {
          s += Vorz*1.0;
          Vorz = -Vorz;
        } // for

       t2 =  System.currentTimeMillis();
       System.out.println("Vorz=-Vorz: "+ (t2-t1) );
    }  // Test2


     // init und Start  if-Anweisung
    public void Test3() {
      long t1, t2;
      double s = 0.0;
      boolean b=true;
       t1 =  System.currentTimeMillis();
        for (int k=0; k<Max; k++) {
          if ( b )
            s += 1.0;
          else
            s -= 1.0;
          b = !b;
        } // for

       t2 =  System.currentTimeMillis();
       System.out.println( "Negation: "+(t2-t1) );
    }  // Test3


     // init und Start   Math.pow
    public void Test4() {
      long t1, t2;
      double s = 0.0;
       t1 =  System.currentTimeMillis();
        for (int k=0; k<Max; k++) {
          s +=  Math.pow(-1,k)*1.0;
        } // for

       t2 =  System.currentTimeMillis();
       System.out.println( "Math.pow:  "+(t2-t1) );
    }  // Test4


     // init und Start   Math.pow
    public void Test5() {
      long t1, t2;
      double s1 = 0.0, s2 = 0.0;
       t1 =  System.currentTimeMillis();
        for (int k=0; k<Max; k+=2) {
            s1 += 1.0;
        } // for
        for (int k=1; k<Max; k+=2) {
            s2 += 1.0;
        } // for

       t2 =  System.currentTimeMillis();
       System.out.println( "s1 / s2:  "+(t2-t1) );
    }  // Test4



  private static void pause() {
    try {
      System.in.read();
    }
    catch (IOException e) {
    }
  }


	public static void main(String[] args) {
    Timer3 timer;
    timer =  new Timer3();
    pause();
  }


}
/*
Modulo: 17866
Vorz=-Vorz: 18266
Negation: 17585
Math.pow:  28792
*/
