Hallo Leute,
ich programmier zwar schon ne Weile in Java, aber für mein Problem weiss ich jetzt auch keien Lösung mehr.
Da ich eine kleine Anwendung zur Bilderkennung in Java
D) schreibe und mir langsam die Bearbeitungszeiten bei den vielen Pixeloperationen zu lang werden, muss ich das bisher Geschriebene etwas optimieren.
Um rauszufinden, ob ich die Pixeloperationen lieber auf Arrays, Listen oder Vars mache, hatte ich flux ne kleine Klasse geschrieben, die mir das für je X Wiederholungen ausgeben sollte, und das möglichst ohne Verfälschungen durch das BS und sein Scheduling.
Als Ergebnis bekomme ich aber nur eine (fast) immer gleiche Durchschnittszugriffszeit von 1000 ns.
Und das kann ich mir beim besten Willen nicht vorstellen.
Das ist, was ich nach den letzten Codeänderungen bekam:
gib zahl ein!
45
used9109
used9448
used11354
alibival: 2114748113
arrayAccess: 1000(6 Corrections)
listAccess: 1000(18 Corrections)
varAccess: 1000(13 Corrections)
270089 Failures occurred
Da ist der Code:
Hoffe ihr könnt das Dilemma klären, und mir Vorschläge für nen glaubwürdigen Test geben.
Bzw: kann ich den Optimizer durch eine vm-variable abschalten?
LG Muckefuck
ich programmier zwar schon ne Weile in Java, aber für mein Problem weiss ich jetzt auch keien Lösung mehr.
Da ich eine kleine Anwendung zur Bilderkennung in Java
Um rauszufinden, ob ich die Pixeloperationen lieber auf Arrays, Listen oder Vars mache, hatte ich flux ne kleine Klasse geschrieben, die mir das für je X Wiederholungen ausgeben sollte, und das möglichst ohne Verfälschungen durch das BS und sein Scheduling.
Als Ergebnis bekomme ich aber nur eine (fast) immer gleiche Durchschnittszugriffszeit von 1000 ns.
Und das kann ich mir beim besten Willen nicht vorstellen.
Das ist, was ich nach den letzten Codeänderungen bekam:
gib zahl ein!
45
used9109
used9448
used11354
alibival: 2114748113
arrayAccess: 1000(6 Corrections)
listAccess: 1000(18 Corrections)
varAccess: 1000(13 Corrections)
270089 Failures occurred
Java:
package tests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class AccessComparision {
static int var = 0;
static int negNanoTimeFailures = 0;
static int correction = 0;
// 1000
// alibival: 1496501
// arrayAccess: 137
// listAccess: 268
// varAccess: 172
// 2433 Failures occurred
// 10000
// alibival: 149965001
// arrayAccess: 149
// listAccess: 246
// varAccess: 164
// 24650 Failures occurred
// 100000
// alibival: 2114748113
// arrayAccess: 81
// listAccess: 89
// varAccess: 83
// 269552 Failures occurred
// Zuletzt
// 100000
// gib zahl ein!
// 45
// used9109
// used9448
// used11354
// alibival: 2114748113
// arrayAccess: 1000(6 Corrections)
// listAccess: 1000(18 Corrections)
// varAccess: 1000(13 Corrections)
// 270089 Failures occurred
public static void main(String[] args) {
//********************************************************************
// Zur Behinderung des Optimizers
int eingabe = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("gib zahl ein!");
try {
String inLine = in.readLine();
eingabe = Integer.parseInt(inLine.trim());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//********************************************************************
int repeats = 100000;
long arrayTime = 0;
long varTime = 0;
long listTime = 0;
long[] arrayTimeArr = new long[repeats];
long[] varTimeArr = new long[repeats];
long[] listTimeArr = new long[repeats];
long start = 0;
long end = 0;
int[] varArr = new int[repeats];
ArrayList<Integer> varList = new ArrayList<Integer>();
int var2 = 0;
for (int var2Set = 0; var2Set < repeats; var2Set++) {
varArr[var2Set] = var2;
varList.add(new Integer(var2++));
}
int intResult;
Integer integerResult = null;
int alibiVal = 1; // Zur Behinderung des Optimizers
for (int i = 0; i < repeats; i++) {
start = System.nanoTime();
intResult = varArr[i];
end = System.nanoTime();
alibiVal += intResult - 2; // Zur Behinderung des Optimizers
arrayTimeArr[i] = end - start;
start = System.nanoTime();
intResult = getVar();
end = System.nanoTime();
var++; //brauche nur Zugriff- nicht Zugriff+Manipulationszeit
alibiVal += intResult + intResult; // Zur Behinderung des Optimizers
varTimeArr[i] = end - start;
start = System.nanoTime();
integerResult = varList.get(i);
end = System.nanoTime();
alibiVal += integerResult.intValue() - intResult; // Zur Behinderung des Optimizers
listTimeArr[i] = end - start;
}
int arrayTimeCorrections = 0;
int varTimeCorrections = 0;
int listTimeCorrections = 0;
arrayTime = getAverageAccessTime(arrayTimeArr, repeats);
arrayTimeCorrections = correction;
correction = 0;
varTime = getAverageAccessTime(varTimeArr, repeats);
varTimeCorrections = correction;
correction = 0;
listTime = getAverageAccessTime(listTimeArr, repeats);
listTimeCorrections = correction;
correction = 0;
System.out.println("alibival: " + alibiVal); // Zur Behinderung des Optimizers
System.out.println("arrayAccess: " + arrayTime + "(" + arrayTimeCorrections + " Corrections)");
System.out.println("listAccess: " + listTime + "(" + listTimeCorrections + " Corrections)");
System.out.println("varAccess: " + varTime + "(" + varTimeCorrections + " Corrections)");
System.out.println(negNanoTimeFailures + " Failures occurred");
}
public static int getVar() {
return var;
}
public static long getAverageAccessTime(long[] times, int repeats) {
long res = 0;
int usedVals = 0;
for (int resIndex = 0; resIndex < repeats; resIndex++) {
if (times[resIndex] <= 0) {//unsinnige Zugriffszeiten ignorieren
// res += 1;
negNanoTimeFailures++;
} else {
res += times[resIndex];
usedVals++;
}
}
long average = res / usedVals;
for (int resIndex = 0; resIndex < repeats; resIndex++) {
long current = times[resIndex];
if (!(current <= 0)) {
if ((current < average * 0.9) || (current > average * 1.1)) {//"Ausgleich" des BS-Scheduling
res -= current;
res += average;
correction++;
}
}
}
System.out.println("used" + usedVals);
return res / usedVals;
}
}
Hoffe ihr könnt das Dilemma klären, und mir Vorschläge für nen glaubwürdigen Test geben.
Bzw: kann ich den Optimizer durch eine vm-variable abschalten?
LG Muckefuck