You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/11/03 02:11:08 UTC

[GitHub] piyushghai commented on a change in pull request #13095: [MXNET-1041] Add Java benchmark

piyushghai commented on a change in pull request #13095: [MXNET-1041] Add Java benchmark
URL: https://github.com/apache/incubator-mxnet/pull/13095#discussion_r230542164
 
 

 ##########
 File path: scala-package/examples/src/main/java/org/apache/mxnetexamples/javaapi/benchmark/JavaBenchmark.java
 ##########
 @@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mxnetexamples.javaapi.benchmark;
+
+import org.apache.mxnet.javaapi.Context;
+import org.kohsuke.args4j.CmdLineParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class JavaBenchmark {
+
+    private static boolean runBatch = false;
+
+    private static void parse(Object inst, String[] args) {
+        CmdLineParser parser  = new CmdLineParser(inst);
+        try {
+            parser.parseArgument(args);
+        } catch (Exception e) {
+            System.err.println(e.getMessage() + e);
+            parser.printUsage(System.err);
+            System.exit(1);
+        }
+    }
+
+    private static long percentile(int p, long[] seq) {
+        Arrays.sort(seq);
+        int k = (int) Math.ceil((seq.length - 1) * (p / 100.0));
+        return seq[k];
+    }
+
+    private static void printStatistics(long[] inferenceTimes, String metricsPrefix)  {
+
+        double p50 = percentile(50, inferenceTimes) / 1.0e6;
+        double p99 = percentile(99, inferenceTimes) / 1.0e6;
+        double p90 = percentile(90, inferenceTimes) / 1.0e6;
+        long sum = 0;
+        for (long time: inferenceTimes) sum += time;
+        double average = sum / (inferenceTimes.length * 1.0e6);
+
+        System.out.println(
+                String.format("\n%s_p99 %fms\n%s_p90 %fms\n%s_p50 %fms\n%s_average %1.2fms",
+                        metricsPrefix, p99, metricsPrefix, p90,
+                        metricsPrefix, p50, metricsPrefix, average)
+        );
+
+    }
+
+    public static void main(String[] args) {
+        if (args.length < 2) {
+            System.out.println("Please specify model name");
+            return;
+        }
+        String modelName = args[1];
+        InferBase model;
+        if (modelName.equals("ObjectDetection")) {
+            runBatch = true;
+            ObjectDetectionBenchmark inst = new ObjectDetectionBenchmark();
+            parse(inst, args);
+            model = inst;
+        } else {
+            System.out.println("Model name not found! " + modelName);
+            return;
+        }
+        List<Context> context = new ArrayList<Context>();
 
 Review comment:
   This thing can be abstracted out in a separate function, and in the main method you can just call that function : getContext() 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services