Fix non-monotonic elapsed time checks, fixes #108
This commit is contained in:
@@ -42,7 +42,7 @@ public class OpenSetsTest {
|
||||
public void removeAndTest(int amount, IOpenSet[] test, Optional<Collection<PathNode>> mustContain) {
|
||||
double[][] results = new double[test.length][amount];
|
||||
for (int i = 0; i < test.length; i++) {
|
||||
long before = System.currentTimeMillis();
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int j = 0; j < amount; j++) {
|
||||
PathNode pn = test[i].removeLowest();
|
||||
if (mustContain.isPresent() && !mustContain.get().contains(pn)) {
|
||||
@@ -50,7 +50,7 @@ public class OpenSetsTest {
|
||||
}
|
||||
results[i][j] = pn.combinedCost;
|
||||
}
|
||||
System.out.println(test[i].getClass() + " " + (System.currentTimeMillis() - before));
|
||||
System.out.println(test[i].getClass() + " " + (System.nanoTime() / 1000000L - before));
|
||||
}
|
||||
for (int j = 0; j < amount; j++) {
|
||||
for (int i = 1; i < test.length; i++) {
|
||||
@@ -104,10 +104,10 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Insertion");
|
||||
for (IOpenSet set : test) {
|
||||
long before = System.currentTimeMillis();
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < size; i++)
|
||||
set.insert(toInsert[i]);
|
||||
System.out.println(set.getClass() + " " + (System.currentTimeMillis() - before));
|
||||
System.out.println(set.getClass() + " " + (System.nanoTime() / 1000000L - before));
|
||||
//all three take either 0 or 1ms to insert up to 10,000 nodes
|
||||
//linkedlist takes 0ms most often (because there's no array resizing or allocation there, just pointer shuffling)
|
||||
}
|
||||
|
@@ -44,21 +44,21 @@ public class BetterBlockPosTest {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before1 = System.currentTimeMillis();
|
||||
long before1 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos.up();
|
||||
}
|
||||
long after1 = System.currentTimeMillis();
|
||||
long after1 = System.nanoTime() / 1000000L;
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before2 = System.currentTimeMillis();
|
||||
long before2 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos2.up();
|
||||
}
|
||||
long after2 = System.currentTimeMillis();
|
||||
long after2 = System.nanoTime() / 1000000L;
|
||||
System.out.println((after1 - before1) + " " + (after2 - before2));
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class BetterBlockPosTest {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before1 = System.currentTimeMillis();
|
||||
long before1 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos.up(0);
|
||||
pos.up(1);
|
||||
@@ -78,13 +78,13 @@ public class BetterBlockPosTest {
|
||||
pos.up(3);
|
||||
pos.up(4);
|
||||
}
|
||||
long after1 = System.currentTimeMillis();
|
||||
long after1 = System.nanoTime() / 1000000L;
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before2 = System.currentTimeMillis();
|
||||
long before2 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos2.up(0);
|
||||
pos2.up(1);
|
||||
@@ -92,7 +92,7 @@ public class BetterBlockPosTest {
|
||||
pos2.up(3);
|
||||
pos2.up(4);
|
||||
}
|
||||
long after2 = System.currentTimeMillis();
|
||||
long after2 = System.nanoTime() / 1000000L;
|
||||
System.out.println((after1 - before1) + " " + (after2 - before2));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user