[logback-dev] svn commit: r1729 - in logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic: . util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Aug 4 22:15:54 CEST 2008
Author: ceki
Date: Mon Aug 4 22:15:53 2008
New Revision: 1729
Modified:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/BogoPerf.java
Log:
- adjust numbers according to the performance of the host CPU
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java Mon Aug 4 22:15:53 2008
@@ -24,25 +24,25 @@
String localhostName = null;
static long NORMAL_RUN_LENGTH = 1000*1000;
- static long REFERENCE_BIPS = 10000;
+ static long REFERENCE_BIPS = 9324;
public void setUp() throws Exception {
localhostName = InetAddress.getLocalHost().getCanonicalHostName();
}
public void testBasic() {
- loopBasic(NORMAL_RUN_LENGTH);
- double avg = loopBasic(NORMAL_RUN_LENGTH);
+ basicDurationInNanos(NORMAL_RUN_LENGTH);
+ double avg = basicDurationInNanos(NORMAL_RUN_LENGTH);
long referencePerf = 17;
- BogoPerf.assertPerformance(avg, referencePerf, REFERENCE_BIPS);
+ BogoPerf.assertDuration(avg, referencePerf, REFERENCE_BIPS);
//System.out.println("Average log time for disabled statements: "+avg+" nanos.");
}
public void testParameterized() {
- loopBasic(NORMAL_RUN_LENGTH);
- double avg = loopParameterized(NORMAL_RUN_LENGTH);
+ basicDurationInNanos(NORMAL_RUN_LENGTH);
+ double avgDuration = loopParameterized(NORMAL_RUN_LENGTH);
long referencePerf = 36;
- BogoPerf.assertPerformance(avg, referencePerf, REFERENCE_BIPS);
+ BogoPerf.assertDuration(avgDuration, referencePerf, REFERENCE_BIPS);
//System.out.println("Average log time for disabled (parameterized) statements: "+avg+" nanos.");
}
@@ -52,10 +52,10 @@
double avg = loopNopFilter(NORMAL_RUN_LENGTH);
//System.out.println("Average log time for disabled (NOPFilter) statements: "+avg+" nanos.");
long referencePerf = 48;
- BogoPerf.assertPerformance(avg, referencePerf, REFERENCE_BIPS);
+ BogoPerf.assertDuration(avg, referencePerf, REFERENCE_BIPS);
}
- double loopBasic(long len) {
+ double basicDurationInNanos(long len) {
LoggerContext lc = new LoggerContext();
NOPAppender<LoggingEvent> mopAppender = new NOPAppender<LoggingEvent>();
mopAppender.start();
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/BogoPerf.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/BogoPerf.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/BogoPerf.java Mon Aug 4 22:15:53 2008
@@ -19,7 +19,7 @@
}
/**
- * compute bogoInstructions per second
+ * Compute bogoInstructions per second
* <p>
* on a 3.2 Ghz Pentium D CPU (around 2007), we obtain about 10'000 bogoIPS.
*
@@ -69,20 +69,54 @@
return (2 * lastBogos + INITIAL_BOGO_IPS) / 3;
}
+ /**
+ * Assertion used for values that <b>decrease</b> with faster CPUs,
+ * typically the time (duration) needed to perform a task.
+ *
+ * @param currentDuration
+ * @param referenceDuraion
+ * @param referenceBIPS
+ * @throws AssertionFailedError
+ */
+ public static void assertDuration(double currentDuration,
+ long referenceDuraion, double referenceBIPS)
+ throws AssertionFailedError {
+ double ajustedDuration = adjustExpectedDuration(referenceDuraion,
+ referenceBIPS);
+ if (currentDuration > ajustedDuration * SLACK) {
+ throw new AssertionFailedError(currentDuration + " exceeded expected "
+ + ajustedDuration + " (adjusted), " + referenceDuraion + " (raw)");
+ }
+ }
+ /**
+ * Assertion used for values that <b>increase<b> with faster CPUs, typically
+ * the number of operations accomplished per unit of time.
+ *
+ * @param currentPerformance
+ * @param referencePerformance
+ * @param referenceBIPS
+ * @throws AssertionFailedError
+ */
public static void assertPerformance(double currentPerformance,
- long referencePerf, double referenceBIPS)
+ long referencePerformance, double referenceBIPS)
throws AssertionFailedError {
- double ajustedPerf = adjustExpectedValue(referencePerf,
+ double ajustedPerf = adjustExpectedPerformance(referencePerformance,
referenceBIPS);
- if (currentPerformance > ajustedPerf * SLACK) {
- throw new AssertionFailedError(currentPerformance + " exceeded expected "
- + ajustedPerf + " (adjusted), " + referencePerf + " (raw)");
+ if (currentPerformance*SLACK < ajustedPerf) {
+ throw new AssertionFailedError(currentPerformance + " below expected "
+ + ajustedPerf + " (adjusted), " + referencePerformance + " (raw)");
}
}
-
- private static double adjustExpectedValue(long referencePerf,
+
+ private static double adjustExpectedPerformance(long referenceDuration,
+ double referenceBIPS) {
+ double currentBIPS = currentBIPS();
+ return referenceDuration * (currentBIPS/referenceBIPS);
+ }
+
+ private static double adjustExpectedDuration(long referenceDuration,
double referenceBIPS) {
double currentBIPS = currentBIPS();
- return referencePerf * (referenceBIPS / currentBIPS);
+ return referenceDuration * (referenceBIPS / currentBIPS);
}
}
More information about the logback-dev
mailing list