/** *ExerciseObject.wait(),comparingresultsagainstwallclocktime.
*/ publicclass Main { /* delays, in milliseconds */ privatefinalstaticlong[] DELAYS = { 200, 500, 1000, 2000, 3500, 8000
}; // This test is inherently prone to failures through scheduling delays and spurious wakeups. // We try it repeatedly, and check that failures are "rare enough". // Currently we go for success on the first try or 2 out of 3. privatefinalstaticint NUM_TRIES = 3; privatefinalstaticint MAX_FAILURES = 1; privatefinalstaticint NANOS_PER_MILLI = 1_000_000;
// Allow a random scheduling delay of up to 400 msecs. That value is empirically determined // from failure logs, though we do get occasional violations. // We seem to get very occasional very long delays on host, perhaps due to getting paged out. privatefinalstaticint MAX_SCHED_MILLIS = 400;
if (timing) {
elapsed_to_report = elapsed;
} else { if (elapsed < min || elapsed > max) {
++ num_failures;
elapsed_to_report = elapsed;
} elseif (i == 0) { // Save time if we immediately succeeded. break;
}
}
} if (num_failures > MAX_FAILURES) {
System.out.println("Failed " + num_failures + " times out of "
+ NUM_TRIES + " tries.");
showTime = true; if (elapsed_to_report < min) { // This can legitimately happen due to premature wake-ups. // This seems rare and unexpected enough in practice that we should // still report if it occurs repeatedly.
System.out.println(" Elapsed time was too short");
} elseif (elapsed_to_report > max) {
System.out.println(" Elapsed time was too long: "
+ "elapsed = " + elapsed_to_report + " max = " + max);
}
} if (showTime) {
System.out.println(" Wall clock elapsed "
+ elapsed_to_report + "ms");
}
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.