mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [07/14] incubator-mnemonic git commit: MNEMONIC-155: Support mode, input and output parameters for sort-bench
Date Mon, 21 Nov 2016 17:32:33 GMT
MNEMONIC-155: Support mode, input and output parameters for sort-bench


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/4e02a15b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/4e02a15b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/4e02a15b

Branch: refs/heads/master
Commit: 4e02a15b11c68b806efb9db5b92f66da4e7f5eed
Parents: 07aace8
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Wed Nov 9 11:02:37 2016 -0800
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Thu Nov 17 12:50:31 2016 -0800

----------------------------------------------------------------------
 mnemonic-benches/mnemonic-sort-bench/pom.xml    |  14 ++-
 .../java/org/apache/mnemonic/bench/Sort.java    | 102 ++++++++++++++++++-
 mnemonic-benches/pom.xml                        |   4 +
 pom.xml                                         |   5 +
 4 files changed, 119 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4e02a15b/mnemonic-benches/mnemonic-sort-bench/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-benches/mnemonic-sort-bench/pom.xml b/mnemonic-benches/mnemonic-sort-bench/pom.xml
index 06bc239..b4aed55 100644
--- a/mnemonic-benches/mnemonic-sort-bench/pom.xml
+++ b/mnemonic-benches/mnemonic-sort-bench/pom.xml
@@ -32,6 +32,12 @@
   <name>mnemonic-sort-bench</name>
   <packaging>jar</packaging>
 
+  <properties>
+    <mode></mode>
+    <input></input>
+    <output></output>
+  </properties>
+
   <dependencies>
   </dependencies>
 
@@ -134,11 +140,17 @@
             <configuration>
               <executable>java</executable>
               <arguments>
-		<argument>-Djava.ext.dirs=${project.build.directory}/service-dist</argument>
+                <argument>-Djava.ext.dirs=${project.build.directory}/service-dist</argument>
                 <argument>-ea</argument>
                 <argument>-classpath</argument>
                 <classpath />
                 <argument>${project.groupId}.bench.Sort</argument>
+                <argument>-m</argument>
+                <argument>${mode}</argument>
+                <argument>-i</argument>
+                <argument>${input}</argument>
+                <argument>-o</argument>
+                <argument>${output}</argument>
               </arguments>
             </configuration>
           </plugin>

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4e02a15b/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/Sort.java
----------------------------------------------------------------------
diff --git a/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/Sort.java
b/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/Sort.java
index 9e44c4e..8f6e4ef 100644
--- a/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/Sort.java
+++ b/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/Sort.java
@@ -17,8 +17,21 @@
 
 package org.apache.mnemonic.bench;
 
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
 import java.util.Random;
-
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.FileNotFoundException;
 
 /**
  * Main is the class of example.
@@ -28,15 +41,94 @@ import java.util.Random;
 public class Sort {
 
   /**
-   * Run a example code to demonstrate some basic functionalities.
+   * Run workloads to bench performance.
    *
-   * @param argv
+   * @param args
    *          array of commandline parameters
    */
-  public static void main(String[] argv) throws Exception {
+  public static void main(String[] args) throws Exception {
     Random randomGenerator = new Random();
 
-    System.out.println("-------------------");
+    Options options = new Options();
+
+    Option mode = new Option("m", "mode", true, "run mode [A|B]");
+    mode.setRequired(true);
+    options.addOption(mode);
+
+    Option input = new Option("i", "input", true, "input file path");
+    input.setRequired(true);
+    options.addOption(input);
+
+    Option output = new Option("o", "output", true, "output file");
+    output.setRequired(true);
+    options.addOption(output);
+
+    CommandLineParser parser = new DefaultParser();
+    HelpFormatter formatter = new HelpFormatter();
+    CommandLine cmd;
+
+    String runMode, inputFilePath, outputFilePath;
+
+    try {
+        cmd = parser.parse(options, args);
+        runMode = cmd.getOptionValue("mode");
+        inputFilePath = cmd.getOptionValue("input");
+        outputFilePath = cmd.getOptionValue("output");
+        if (!runMode.equals("A") && !runMode.equals("B")) {
+          throw new ParseException("Run mode is not specified correctly, Please use A or
B as run mode.");
+        }
+    } catch (ParseException e) {
+        System.out.println(e.getMessage());
+        formatter.printHelp("Sort-bench", options);
+        System.exit(1);
+        return;
+    }
+
+    System.out.println(String.format("Run Mode is %s", runMode));
+    System.out.println(String.format("Input file is %s", inputFilePath));
+    System.out.println(String.format("Output file is %s", outputFilePath));
+
+    File inputFile = new File(inputFilePath);
+    File outputFile = new File(outputFilePath);
+
+    BufferedReader reader = null;
+    BufferedWriter writer = null;
+
+    try {
+      reader = new BufferedReader(new FileReader(inputFile));
+      writer = new BufferedWriter(new FileWriter(outputFile));
+      if (runMode.equals("A")) {
+        /* regular way */
+        String text = null;
+        while ((text = reader.readLine()) != null) {
+          System.out.println(text);
+          writer.write(text);
+          writer.newLine();
+        }
+      } else {
+        /* mnemonic way */
+        System.out.println("mnemonic way");
+      }
+    } catch (FileNotFoundException e) {
+      System.err.println(e.getMessage());
+      throw e;
+    } catch (IOException e) {
+      System.err.println(e.getMessage());
+      throw e;
+    } finally {
+      try {
+        if (null != reader) {
+          reader.close();
+        }
+        if (null != writer) {
+          writer.close();
+        }
+      } catch (IOException e) {
+        System.err.println(e.getMessage());
+        throw e;
+      }
+    }
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4e02a15b/mnemonic-benches/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-benches/pom.xml b/mnemonic-benches/pom.xml
index 899bb2a..9c5a664 100644
--- a/mnemonic-benches/pom.xml
+++ b/mnemonic-benches/pom.xml
@@ -48,6 +48,10 @@
       <artifactId>mnemonic-core</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+    </dependency>
     <!-- logging dependencies -->
     <!-- assume all APIs will be used -->
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4e02a15b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 33e946a..04df5c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -137,6 +137,11 @@
         <version>0.6.1</version>
       </dependency>
       <dependency>
+        <groupId>commons-cli</groupId>
+        <artifactId>commons-cli</artifactId>
+        <version>1.3.1</version>
+      </dependency>
+      <dependency>
         <groupId>com.squareup</groupId>
         <artifactId>javapoet</artifactId>
         <version>1.6.1</version>


Mime
View raw message