This commit is contained in:
2023-04-05 13:37:19 +02:00
parent cc7a05fa0e
commit 1f055e3030
13 changed files with 335 additions and 85 deletions

8
untitled/src/Main.java Normal file
View 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
View 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;
}
}

View 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);
}
}