Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 256B5200BEA for ; Mon, 21 Nov 2016 18:32:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 241E1160AEF; Mon, 21 Nov 2016 17:32:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2CA8F160AF9 for ; Mon, 21 Nov 2016 18:32:33 +0100 (CET) Received: (qmail 74189 invoked by uid 500); 21 Nov 2016 17:32:32 -0000 Mailing-List: contact commits-help@mnemonic.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mnemonic.incubator.apache.org Delivered-To: mailing list commits@mnemonic.incubator.apache.org Received: (qmail 74167 invoked by uid 99); 21 Nov 2016 17:32:32 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Nov 2016 17:32:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id EC480180519 for ; Mon, 21 Nov 2016 17:32:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id cqVVZcpAGEbe for ; Mon, 21 Nov 2016 17:32:30 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E5BED5FAD2 for ; Mon, 21 Nov 2016 17:32:28 +0000 (UTC) Received: (qmail 71535 invoked by uid 99); 21 Nov 2016 17:32:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Nov 2016 17:32:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E2087F16A7; Mon, 21 Nov 2016 17:32:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garyw@apache.org To: commits@mnemonic.incubator.apache.org Date: Mon, 21 Nov 2016 17:32:33 -0000 Message-Id: <75acb497fc0f44899cd4e2e6b53c1776@git.apache.org> In-Reply-To: <36f7435d01f747b1bd93f2124736ac20@git.apache.org> References: <36f7435d01f747b1bd93f2124736ac20@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/14] incubator-mnemonic git commit: MNEMONIC-155: Support mode, input and output parameters for sort-bench archived-at: Mon, 21 Nov 2016 17:32:34 -0000 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) Authored: Wed Nov 9 11:02:37 2016 -0800 Committer: Wang, Gang(Gary) 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 @@ mnemonic-sort-bench jar + + + + + + @@ -134,11 +140,17 @@ java - -Djava.ext.dirs=${project.build.directory}/service-dist + -Djava.ext.dirs=${project.build.directory}/service-dist -ea -classpath ${project.groupId}.bench.Sort + -m + ${mode} + -i + ${input} + -o + ${output} 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 @@ mnemonic-core ${project.version} + + commons-cli + commons-cli + 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 @@ 0.6.1 + commons-cli + commons-cli + 1.3.1 + + com.squareup javapoet 1.6.1