Example usage for java.lang System currentTimeMillis

List of usage examples for java.lang System currentTimeMillis

Introduction

In this page you can find the example usage for java.lang System currentTimeMillis.

Prototype

@HotSpotIntrinsicCandidate
public static native long currentTimeMillis();

Source Link

Document

Returns the current time in milliseconds.

Usage

From source file:com.dlej.Main.java

public static void main(String[] args) {
    long startTime = System.currentTimeMillis();

    // initialize a new genetic algorithm
    GeneticAlgorithm ga = new GeneticAlgorithm(new OnePointCrossover<Character>(), CROSSOVER_RATE,
            new RandomCharacterMutation(), MUTATION_RATE, new TournamentSelection(TOURNAMENT_ARITY));

    // initial population
    Population initial = getInitialPopulation();

    // stopping condition
    StoppingCondition stoppingCondition = new StoppingCondition() {

        int generation = 0;

        @Override//from ww w  .  j  a va 2 s.  com
        public boolean isSatisfied(Population population) {
            Chromosome fittestChromosome = population.getFittestChromosome();

            if (generation == 1 || generation % 10 == 0) {
                System.out.println("Generation " + generation + ": " + fittestChromosome.toString());
            }
            generation++;

            double fitness = fittestChromosome.fitness();
            if (Precision.equals(fitness, 0.0, 1e-6)) {
                return true;
            } else {
                return false;
            }
        }
    };

    System.out.println("Starting evolution ...");

    // run the algorithm
    Population finalPopulation = ga.evolve(initial, stoppingCondition);

    // Get the end time for the simulation.
    long endTime = System.currentTimeMillis();

    // best chromosome from the final population
    Chromosome best = finalPopulation.getFittestChromosome();
    System.out.println("Generation " + ga.getGenerationsEvolved() + ": " + best.toString());
    System.out.println("Total execution time: " + (endTime - startTime) + "ms");
}

From source file:org.eclipse.swt.snippets.Snippet201.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 201");
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
    table.addListener(SWT.SetData, event -> {
        TableItem item = (TableItem) event.item;
        int index = table.indexOf(item);
        int start = index / PAGE_SIZE * PAGE_SIZE;
        int end = Math.min(start + PAGE_SIZE, table.getItemCount());
        for (int i = start; i < end; i++) {
            item = table.getItem(i);/*from  w ww  . ja  va  2s  .  co  m*/
            item.setText("Item " + i);
        }
    });
    table.setLayoutData(new RowData(200, 200));
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Add Items");
    final Label label = new Label(shell, SWT.NONE);
    button.addListener(SWT.Selection, event -> {
        long t1 = System.currentTimeMillis();
        table.setItemCount(COUNT);
        long t2 = System.currentTimeMillis();
        label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]");
        shell.layout();
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.opencredo.esper.samples.noodlebar.main.SyncNoodleOrderGenerator.java

public static void main(String[] args) {

    System.out.println("Initializing Dependencies...");

    initializeDependencies();//from  ww  w.  ja  v a 2s  .  co  m

    long startTime = System.currentTimeMillis();

    System.out.println("Sending orders into the Noodle Bar...");

    sendSomeOrders();

    long stopTime = System.currentTimeMillis();

    long timeTaken = stopTime - startTime;

    System.out.println("Simple timer calculated at end " + timeTaken + " milliseconds for " + NUMBER_OF_ORDERS
            + " orders");

    System.out.println(
            "The Noodle Bar is actually processing " + noodleOrderThroughputMonitor.getAverageThroughput()
                    + " orders per second according to continuous Esper Monitoring");

    System.exit(0);
}

From source file:com.sangupta.resumemaker.ResumeMaker.java

/**
 * @param args//w w  w  .  j  av a 2s .  co  m
 */
public static void main(String[] args) throws Exception {
    Config config = new Config();

    // linkedin
    config.linkedInConfig.consumerKey = "3nzfrdq9qj8n";
    config.linkedInConfig.consumerSecret = "sees0f8pPyU2GW1E";
    config.linkedInConfig.userName = "sangupta";

    // github
    config.gitHubConfig.userName = "sangupta";

    // gravatar
    config.gravatarID = "sandy.pec@gmail.com";

    UserData userData = null;

    if (!useCachedData) {
        final long startTime = System.currentTimeMillis();
        System.out.println("Start fetching user data at " + startTime);
        userData = gatherUserData(config);
        final long endTime = System.currentTimeMillis();
        System.out.println(
                "Start fetching user data at " + endTime + ", time taken " + (endTime - startTime) + " ms.");

        writeUserData(userData);
    }

    userData = readUserData();

    File exportFile = new File("resume.html");

    System.out.print("Exporting the resume... ");
    Exporter exporter = new HtmlExport();
    exporter.export(userData, exportFile);
    System.out.println("done!");

    //      BrowserUtil.openUrlInBrowser("file:///" + exportFile.getAbsolutePath());
}

From source file:org.opencredo.esper.samples.noodlebar.main.AsyncNoodleOrderGenerator.java

public static void main(String[] args) {

    System.out.println("Initializing Dependencies...");

    initializeDependencies();//  w  w  w.jav  a 2s . co  m

    long startTime = System.currentTimeMillis();

    System.out.println("Sending orders into the Noodle Bar...");

    sendSomeOrders();

    long stopTime = System.currentTimeMillis();

    long timeTaken = stopTime - startTime;

    System.out.println("Simple timer calculated at end " + timeTaken + " milliseconds for " + NUMBER_OF_ORDERS
            + " orders");

    System.out.println(
            "The Noodle Bar is actually accepting " + noodleOrderThroughputMonitor.getAverageThroughput()
                    + " orders per second according to continuous Esper Monitoring");

    System.exit(0);
}

From source file:com.damon.rocketmq.example.operation.Producer.java

public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();//w w w.ja v a  2 s  .  c o m

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(topic, tags, keys,
                        ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
                SendResult sendResult = producer.send(msg);
                System.out.printf("%-8d %s%n", i, sendResult);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}

From source file:com.matthatem.ai.search.applications.MSASolver.java

public static void main(String[] args) {
    Options options = createOptions();//from  w ww  . j a  va2s .  co  m
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(1);
    }

    MSA msa = createMSAInstance(cmd);
    SearchAlgorithm algo = createSearchAlgorithm(cmd, msa);

    System.gc();

    long t = System.currentTimeMillis();
    SearchResult<MSAState> result = algo.search();
    long td = System.currentTimeMillis();

    result.setAlgorithm(algoString);
    result.setInitialH((int) msa.getHeuristic().getInitH());
    result.setStartTime(t);
    result.setEndTime(td);

    System.out.println(result);
    //System.out.println(msa.alignmentToString());
    System.out.println(msa.alignmentToMSFString());
}

From source file:com.glaf.core.xml.XmlBuilder.java

public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();
    String systemName = "default";

    XmlBuilder builder = new XmlBuilder();
    InputStream in = new FileInputStream("./template/user.template.xml");
    String filename = "user.xml";
    byte[] bytes = FileUtils.getBytes(in);
    Map<String, Object> dataMap = new HashMap<String, Object>();
    dataMap.put("now", new Date());
    Document doc = builder.process(systemName, new ByteArrayInputStream(bytes), dataMap);
    FileUtils.save(filename, com.glaf.core.util.Dom4jUtils.getBytesFromPrettyDocument(doc, "GBK"));
    // net.sf.json.xml.XMLSerializer xmlSerializer = new
    // net.sf.json.xml.XMLSerializer();
    // net.sf.json.JSON json = xmlSerializer.read(doc.asXML());
    // System.out.println(json.toString(1));

    long time = (System.currentTimeMillis() - start) / 1000;
    System.out.println("times:" + time + " seconds");
}

From source file:com.nubits.nubot.launch.MainLaunch.java

/**
 * Start the NuBot. start if config is valid and other instance is running
 *
 * @param args a list of valid arguments
 *//*from  ww  w  .j  a v a 2 s  . co m*/
public static void main(String args[]) {

    Global.sessionPath = "logs" + "/" + Settings.SESSION_LOG + System.currentTimeMillis();
    MDC.put("session", Global.sessionPath);
    LOG.info("defined session path " + Global.sessionPath);

    CommandLine cli = parseArgs(args);

    boolean runGUI = false;
    String configFile;

    boolean defaultCfg = false;
    if (cli.hasOption(CLIOptions.GUI)) {
        runGUI = true;
        LOG.info("Running " + Settings.APP_NAME + " with GUI");

        if (!cli.hasOption(CLIOptions.CFG)) {
            LOG.info("Setting default config file location :" + Settings.DEFAULT_CONFIG_FILE_PATH);
            //Cancel any previously existing file, if any
            File f = new File(Settings.DEFAULT_CONFIG_FILE_PATH);
            if (f.exists() && !f.isDirectory()) {
                LOG.warn("Detected a non-empty configuration file, resetting it to default. "
                        + "Printing existing file content, for reference:\n"
                        + FilesystemUtils.readFromFile(Settings.DEFAULT_CONFIG_FILE_PATH));
                FilesystemUtils.deleteFile(Settings.DEFAULT_CONFIG_FILE_PATH);
            }
            //Create a default file
            SaveOptions.optionsReset(Settings.DEFAULT_CONFIG_FILE_PATH);
            defaultCfg = true;
        }
    }
    if (cli.hasOption(CLIOptions.CFG) || defaultCfg) {
        if (defaultCfg) {
            configFile = Settings.DEFAULT_CONFIG_FILE_PATH;
        } else {
            configFile = cli.getOptionValue(CLIOptions.CFG);
        }

        if (runGUI) {
            SessionManager.setConfigGlobal(configFile, true);
            try {
                UiServer.startUIserver(configFile, defaultCfg);
                Global.createShutDownHook();
            } catch (Exception e) {
                LOG.error("error setting up UI server " + e);
            }

        } else {
            LOG.info("Run NuBot from CLI");
            //set global config
            SessionManager.setConfigGlobal(configFile, false);
            sessionLOG.debug("launch bot");
            try {
                SessionManager.setModeStarting();
                SessionManager.launchBot(Global.options);
                Global.createShutDownHook();
            } catch (NuBotRunException e) {
                exitWithNotice("could not launch bot " + e);
            }
        }

    } else {
        exitWithNotice("Missing " + CLIOptions.CFG + ". run nubot with \n" + CLIOptions.USAGE_STRING);
    }

}

From source file:TableWithPageSize.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
    table.addListener(SWT.SetData, new Listener() {
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = table.indexOf(item);
            int start = index / PAGE_SIZE * PAGE_SIZE;
            int end = Math.min(start + PAGE_SIZE, table.getItemCount());
            for (int i = start; i < end; i++) {
                item = table.getItem(i);
                item.setText("Item " + i);
            }//from   w w w .  java 2s. c o  m
        }
    });
    table.setLayoutData(new RowData(200, 200));
    long t1 = System.currentTimeMillis();
    table.setItemCount(COUNT);
    long t2 = System.currentTimeMillis();
    System.out.println("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]");
    shell.layout();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}