Example usage for java.lang System nanoTime

List of usage examples for java.lang System nanoTime

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native long nanoTime();

Source Link

Document

Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.

Usage

From source file:apiserver.services.pdf.service.UrlToPdfCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    Url2PdfResult props = (Url2PdfResult) message.getPayload();

    try {//  ww w.  j ava  2  s . c o  m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'coldfusion-worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec.submit(new UrlToPdfCallable(props.getPath(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:net.openhft.chronicle.logger.log4j1.Log4j1IndexedChroniclePerfTest.java

@Test
public void testSingleThreadLogging1() throws IOException {
    Thread.currentThread().setName("perf-plain-indexed");

    final String testId = "perf-binary-indexed-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final Logger plogger = LoggerFactory.getLogger("perf-plain-indexed");
    final long items = 1000000;

    warmup(clogger);//w  ww .  ja  va 2 s.  c om
    warmup(plogger);

    for (int s = 64; s <= 1024; s += 64) {
        final String staticStr = StringUtils.leftPad("", s, 'X');

        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(staticStr);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(staticStr);
        }

        long pEnd1 = System.nanoTime();

        System.out.printf(
                "items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us, plain=%d, plain-average=%.3f us\n",
                items, staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3,
                (pEnd1 - pStart1), (pEnd1 - pStart1) / items / 1e3);
    }

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:apiserver.services.pdf.service.GetPdfInfoCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    PdfGetInfoResult props = (PdfGetInfoResult) message.getPayload();

    try {/* w  w w. j a  va2 s  .c  om*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<MapResult> future = exec
                .submit(new GetInfoCallable(props.getFile().getFileBytes(), props.getOptions()));

        MapResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getData());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:apiserver.services.pdf.service.ProcessPdfDDXCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    DDXPdfResult props = (DDXPdfResult) message.getPayload();

    try {//from  w  w w  .ja  v a2 s.  c o m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec
                .submit(new ProcessDDXCallable(props.getFile().getFileBytes(), props.getDdx()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:apiserver.services.pdf.service.SetPdfInfoCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    PdfSetInfoResult props = (PdfSetInfoResult) message.getPayload();

    try {/*from  w  w w .j  a  va2  s  .  c o m*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<MapResult> future = exec
                .submit(new SetInfoCallable(props.getFile().getFileBytes(), props.getOptions()));

        MapResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getData());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:apiserver.services.pdf.service.HtmlToPdfCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    Html2PdfResult props = (Html2PdfResult) message.getPayload();

    try {//from w w  w  . j  a va 2s .  co m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec.submit(new HtmlToPdfCallable(props.getHtml(),
                props.getHeaderHtml(), props.getFooterHtml(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:gridool.mapred.db.DBReduceJob.java

public Map<GridTask, GridNode> map(GridRouter router, DBMapReduceJobConf jobConf) throws GridException {
    final String inputTableName = jobConf.getMapOutputTableName();
    String destTableName = jobConf.getReduceOutputTableName();
    if (destTableName == null) {
        destTableName = generateOutputTableName(inputTableName, System.nanoTime());
        jobConf.setReduceOutputTableName(destTableName);
    }/*  ww  w .  ja va 2  s .c  o m*/
    this.destTableName = destTableName;

    final GridNode[] nodes = router.getAllNodes();
    final Map<GridTask, GridNode> map = new IdentityHashMap<GridTask, GridNode>(nodes.length);
    final String createTableTemplate = jobConf.getQueryTemplateForCreatingViewComposite();
    if (createTableTemplate != null) {
        final String dstDbUrl = jobConf.getReduceOutputDbUrl();
        if (dstDbUrl == null) {
            throw new GridException(
                    "ReduceOutputDestinationDbUrl should be specified when using a view in reduce phase");
        }
        final String outputTblName = jobConf.getReduceOutputTableName();
        final StringBuilder createTablesQuery = new StringBuilder(512);
        final StringBuilder createViewQuery = new StringBuilder(512);
        createViewQuery.append("CREATE VIEW ").append(outputTblName).append(" AS");
        final int numNodes = nodes.length;
        for (int i = 0; i < numNodes; i++) {
            if (i != 0) {
                createViewQuery.append(" UNION ALL");
            }
            GridTask task = jobConf.makeReduceTask(this, inputTableName, destTableName);
            task.setTaskNumber(i + 1);
            map.put(task, nodes[i]);
            String newTableName = GridUtils.generateTableName(outputTblName, task);
            String createTableQuery = createTableTemplate.replace("?", newTableName);
            createTablesQuery.append(createTableQuery).append("; ");
            createViewQuery.append(" SELECT * FROM ").append(newTableName);
        }
        createViewQuery.append(';');
        try {
            createView(dstDbUrl, createTablesQuery.toString(), createViewQuery.toString(), jobConf);
        } catch (SQLException e) {
            LOG.error(e.getMessage(), e);
            throw new GridException(e);
        }
    } else {
        for (GridNode node : nodes) {
            GridTask task = jobConf.makeReduceTask(this, inputTableName, destTableName);
            map.put(task, node);
        }
    }
    return map;
}

From source file:net.openhft.chronicle.logger.VanillChronicleQueuePerfTest.java

@Test
public void testMultiThreadLogging() throws IOException, InterruptedException {

    final int RUNS = 15000000;
    final int THREADS = Runtime.getRuntime().availableProcessors();

    for (int size : new int[] { 64, 128, 256 }) {
        {//from ww w . j  a  v a2 s .co  m
            final long start = System.nanoTime();

            ExecutorService es = Executors.newFixedThreadPool(THREADS);
            for (int t = 0; t < THREADS; t++) {
                es.submit(new RunnableLogger(RUNS, size));
            }

            es.shutdown();
            es.awaitTermination(2, TimeUnit.MINUTES);

            final long time = System.nanoTime() - start;

            System.out.printf(
                    "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n",
                    RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS));
        }
    }
}

From source file:apiserver.services.pdf.service.OptimizePdfCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    OptimizePdfResult props = (OptimizePdfResult) message.getPayload();

    try {/*from  w w  w  .  j a v a 2  s.co  m*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec
                .submit(new OptimizePdfCallable(props.getFile().getFileBytes(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:apiserver.services.pdf.service.MergePdfFilesCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    ExtractImageResult props = (ExtractImageResult) message.getPayload();

    try {/*from   w w  w.jav a  2 s . c o m*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<CollectionResult> future = exec
                .submit(new MergePdfCallable(props.getFile().getFileBytes(), props.getOptions()));

        CollectionResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getCollection());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}