aaa
This commit is contained in:
8
untitled/src/Main.java
Normal file
8
untitled/src/Main.java
Normal file
@@ -0,0 +1,8 @@
|
||||
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
|
||||
// then press Enter. You can now see whitespace characters in your code.
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
19
untitled/src/StopUhr.java
Normal file
19
untitled/src/StopUhr.java
Normal file
@@ -0,0 +1,19 @@
|
||||
public class StopUhr
|
||||
{
|
||||
private long startTime, stopTime;
|
||||
|
||||
public void start()
|
||||
{
|
||||
startTime = System.nanoTime();
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
stopTime = System.nanoTime();
|
||||
}
|
||||
|
||||
public long getDuration()
|
||||
{
|
||||
return stopTime - startTime;
|
||||
}
|
||||
}
|
||||
67
untitled/src/Zeitmessung.java
Normal file
67
untitled/src/Zeitmessung.java
Normal file
@@ -0,0 +1,67 @@
|
||||
public class Zeitmessung
|
||||
{
|
||||
static int tuWasCounter = 0;
|
||||
private static double tuwas()
|
||||
{
|
||||
tuWasCounter++;
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
// Linear
|
||||
public static double func1(int n)
|
||||
{
|
||||
double summe = 0;
|
||||
|
||||
for (int a = 0; a < n; a++)
|
||||
summe += tuwas();
|
||||
|
||||
return summe;
|
||||
}
|
||||
|
||||
// Quadratisch
|
||||
public static double func2(int n)
|
||||
{
|
||||
double summe = 0;
|
||||
|
||||
for (int a = 0; a < n; a++)
|
||||
for(int b = 0; b < n; b++)
|
||||
summe += tuwas();
|
||||
|
||||
return summe;
|
||||
}
|
||||
|
||||
// log2(n)
|
||||
public static double func6(int n)
|
||||
{
|
||||
double summe = 0;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
summe += tuwas();
|
||||
n /= 2;
|
||||
}
|
||||
|
||||
return summe;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
StopUhr uhr = new StopUhr();
|
||||
final int n = 100000;
|
||||
tuWasCounter = 0;
|
||||
uhr.start();
|
||||
func1(n);
|
||||
uhr.stop();
|
||||
System.out.println("func1 "+"n="+n+" Zeit:"+uhr.getDuration()+" tuWasCounter:" + tuWasCounter);
|
||||
tuWasCounter = 0;
|
||||
uhr.start();
|
||||
func2(n);
|
||||
uhr.stop();
|
||||
System.out.println("func2 "+"n="+n+" Zeit:"+uhr.getDuration()+" tuWasCounter:" + tuWasCounter);
|
||||
tuWasCounter = 0;
|
||||
uhr.start();
|
||||
func6(n);
|
||||
uhr.stop();
|
||||
System.out.println("func6 "+"n="+n+" Zeit:"+uhr.getDuration()+" tuWasCounter:" + tuWasCounter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user