You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2015/07/31 15:55:30 UTC
svn commit: r1693598 - /devicemap/trunk/clients/2.0/reference/src/Main.java
Author: rezan
Date: Fri Jul 31 13:55:29 2015
New Revision: 1693598
URL: http://svn.apache.org/r1693598
Log:
timings and warmup
Modified:
devicemap/trunk/clients/2.0/reference/src/Main.java
Modified: devicemap/trunk/clients/2.0/reference/src/Main.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Main.java?rev=1693598&r1=1693597&r2=1693598&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Fri Jul 31 13:55:29 2015
@@ -31,8 +31,6 @@ public class Main {
public static void main(String args[]) throws Exception {
log("DeviceMap Reference Client " + DeviceMapClient.VERSION, -1);
- DeviceMapClient client = new DeviceMapClient();
-
List<String> patterns = new ArrayList<>();
List<String> attributes = new ArrayList<>();
List<String> tests = new ArrayList<>();
@@ -40,6 +38,9 @@ public class Main {
String testString = null;
boolean failure = false;
+ int warmup = 0;
+
+ long start, time;
//PARSE THE COMMAND LINE
@@ -57,6 +58,8 @@ public class Main {
tests.add(getParam(args, ++i, "-t file parameter missing"));
} else if(!option.startsWith("-") && testString == null) {
testString = option;
+ } else if(option.equals("-w")) {
+ warmup = 150;
} else if(option.equals("-q")) {
verbose = -1;
} else if(option.equals("-v")) {
@@ -74,8 +77,44 @@ public class Main {
throw new Exception("Pattern file required");
}
+ //WARMUP
+
+ if(warmup > 0) {
+ log("Warmup...", -1);
+
+ int origVerbose = verbose;
+ verbose = -2;
+
+ for(int i = 0; i < warmup; i++) {
+ DeviceMapClient client = new DeviceMapClient();
+
+ for(String pattern : patterns) {
+ client.loadPatterns(new JsonFile(pattern));
+ }
+
+ for(String attribute : attributes) {
+ client.loadAttributes(new JsonFile(attribute));
+ }
+
+ for(String test : tests) {
+ test(client, new JsonFile(test));
+ }
+ }
+
+ System.gc();
+ System.runFinalization();
+
+ verbose = origVerbose;
+
+ log("Warmup completed", -1);
+ }
+
//BUILD THE DEVICEMAP CLIENT
+ start = System.nanoTime();
+
+ DeviceMapClient client = new DeviceMapClient();
+
for(String pattern : patterns) {
log("Pattern file: '" + pattern + "'", 0);
client.loadPatterns(new JsonFile(pattern));
@@ -86,6 +125,9 @@ public class Main {
client.loadAttributes(new JsonFile(attribute));
}
+ time = System.nanoTime() - start;
+ log("Domain load time: " + getTime(time), -1);
+
//DO THE TESTS
for(String test : tests) {
@@ -95,8 +137,15 @@ public class Main {
if(testString != null) {
log("Test string: '" + testString + "'", 0);
+
+ start = System.nanoTime();
+
Map<String, String> result = client.classify(testString);
+
+ time = System.nanoTime() - start;
+
log("Test result: " + result, -1);
+ log("Test time: " + getTime(time), -1);
}
if(failure) {
@@ -110,6 +159,7 @@ public class Main {
log(" -a <file> load DeviceMap 2.0 attribute file", -1);
log(" -t <file> load DeviceMap 2.0 test file", -1);
log(" -h print help", -1);
+ log(" -w JVM warmup", -1);
log(" -q quiet", -1);
log(" -v verbose", -1);
log(" -vv very verbose", -1);
@@ -158,7 +208,11 @@ public class Main {
int testCount = 0;
int passCount = 0;
+ long start, time;
+
//ITERATE THRU THE TESTS
+
+ start = System.nanoTime();
if(JsonFile.get(tests.getJsonNode(), "tests").isArray()) {
for(int i = 0; i < tests.getJsonNode().get("tests").size(); i++) {
@@ -227,8 +281,18 @@ public class Main {
}
}
+ time = System.nanoTime() - start;
+
log("Test passed " + passCount + " out of " + testCount + ". " + (testCount == passCount ? "PASS" : "FAIL"), -1);
+ log("Test time: " + getTime(time), -1);
return testCount != passCount;
}
+
+ public static String getTime(long ns)
+ {
+ return ns / (1000 * 1000 * 1000) + "s " +
+ ns / (1000 * 1000) % 1000 + "ms " +
+ ns / 1000 % 1000 + "." + ns % 1000 + "us";
+ }
}