List of usage examples for java.lang String format
public static String format(Locale l, String format, Object... args)
From source file:com.yahoo.pulsar.testclient.PerformanceReader.java
public static void main(String[] args) throws Exception { final Arguments arguments = new Arguments(); JCommander jc = new JCommander(arguments); jc.setProgramName("pulsar-perf-reader"); try {/*from w w w. j a v a 2s.com*/ jc.parse(args); } catch (ParameterException e) { System.out.println(e.getMessage()); jc.usage(); System.exit(-1); } if (arguments.help) { jc.usage(); System.exit(-1); } if (arguments.topic.size() != 1) { System.out.println("Only one topic name is allowed"); jc.usage(); System.exit(-1); } if (arguments.confFile != null) { Properties prop = new Properties(System.getProperties()); prop.load(new FileInputStream(arguments.confFile)); if (arguments.serviceURL == null) { arguments.serviceURL = prop.getProperty("brokerServiceUrl"); } if (arguments.serviceURL == null) { arguments.serviceURL = prop.getProperty("webServiceUrl"); } // fallback to previous-version serviceUrl property to maintain backward-compatibility if (arguments.serviceURL == null) { arguments.serviceURL = prop.getProperty("serviceUrl", "http://localhost:8080/"); } if (arguments.authPluginClassName == null) { arguments.authPluginClassName = prop.getProperty("authPlugin", null); } if (arguments.authParams == null) { arguments.authParams = prop.getProperty("authParams", null); } } // Dump config variables ObjectMapper m = new ObjectMapper(); ObjectWriter w = m.writerWithDefaultPrettyPrinter(); log.info("Starting Pulsar performance reader with config: {}", w.writeValueAsString(arguments)); final DestinationName prefixTopicName = DestinationName.get(arguments.topic.get(0)); final RateLimiter limiter = arguments.rate > 0 ? RateLimiter.create(arguments.rate) : null; ReaderListener listener = (reader, msg) -> { messagesReceived.increment(); bytesReceived.add(msg.getData().length); if (limiter != null) { limiter.acquire(); } }; EventLoopGroup eventLoopGroup; if (SystemUtils.IS_OS_LINUX) { eventLoopGroup = new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2, new DefaultThreadFactory("pulsar-perf-reader")); } else { eventLoopGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), new DefaultThreadFactory("pulsar-perf-reader")); } ClientConfiguration clientConf = new ClientConfiguration(); clientConf.setConnectionsPerBroker(arguments.maxConnections); clientConf.setStatsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS); if (isNotBlank(arguments.authPluginClassName)) { clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); } PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf, eventLoopGroup); List<CompletableFuture<Reader>> futures = Lists.newArrayList(); ReaderConfiguration readerConfig = new ReaderConfiguration(); readerConfig.setReaderListener(listener); readerConfig.setReceiverQueueSize(arguments.receiverQueueSize); MessageId startMessageId; if ("earliest".equals(arguments.startMessageId)) { startMessageId = MessageId.earliest; } else if ("latest".equals(arguments.startMessageId)) { startMessageId = MessageId.latest; } else { String[] parts = arguments.startMessageId.split(":"); startMessageId = new MessageIdImpl(Long.parseLong(parts[0]), Long.parseLong(parts[1]), -1); } for (int i = 0; i < arguments.numDestinations; i++) { final DestinationName destinationName = (arguments.numDestinations == 1) ? prefixTopicName : DestinationName.get(String.format("%s-%d", prefixTopicName, i)); futures.add(pulsarClient.createReaderAsync(destinationName.toString(), startMessageId, readerConfig)); } FutureUtil.waitForAll(futures).get(); log.info("Start reading from {} topics", arguments.numDestinations); long oldTime = System.nanoTime(); while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { break; } long now = System.nanoTime(); double elapsed = (now - oldTime) / 1e9; double rate = messagesReceived.sumThenReset() / elapsed; double throughput = bytesReceived.sumThenReset() / elapsed * 8 / 1024 / 1024; log.info("Read throughput: {} msg/s -- {} Mbit/s", dec.format(rate), dec.format(throughput)); oldTime = now; } pulsarClient.close(); }
From source file:com.sojw.TableNamesFinderExecutor.java
/** * @param args/*ww w . j a v a2 s . co m*/ */ public static void main(String[] args) throws Exception { List<CSVRecord> fileContentList = null; try { fileContentList = getCSVFileContents(FILE_ROOT_DIR + SOURCE_FILE_NAME); } catch (IOException e) { System.out.println(" ."); System.exit(-1); } if (fileContentList == null || fileContentList.isEmpty()) { System.out.println(" ."); System.exit(1); } // final Set<String> iterMapKeys = iterMap.keySet(); for (final String mapkey : iterMapKeys) { final List<String> iterList = iterMap.get(mapkey); for (final String tableName : iterList) { final List<String> resultList = extractTableNameByRegex(tableName, fileContentList); final String outputFileName = FILE_ROOT_DIR + String.format(OUTPUT_FILE_NAME_FORMAT, mapkey, tableName); FileUtils.deleteQuietly(new File(outputFileName)); FileUtils.writeLines(new File(outputFileName), resultList, false); } } // Zql // final Set<String> iterMapKeys = iterMap.keySet(); // for (String mapkey : iterMapKeys) { // final List<String> iterList = iterMap.get(mapkey); // for (final String tableName : iterList) { // extractTableNameByZql(fileContentList); // } // } }
From source file:ffx.numerics.fft.RowMajorComplex3DCuda.java
/** * <p>/*from w w w .j a v a 2 s . c o m*/ * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[2]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { int index = RowMajorComplex3D.iComplex3D(x, y, z, dim, dim); orig[index / 2] = random.nextDouble(); recip[index / 2] = orig[index / 2]; } } } RowMajorComplex3D complex3D = new RowMajorComplex3D(dim, dim, dim); RowMajorComplex3DParallel complex3DParallel = new RowMajorComplex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); RowMajorComplex3DCuda complex3DCUDA = new RowMajorComplex3DCuda(dim, dim, dim, data, recip); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } complex3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DCUDA.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs((answer[i] - data[2 * i]) / dimCubed); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:Main.java
public static String getDiscount(String text) { return String.format("-%s%s", text, "%"); }
From source file:Main.java
private static String hashKey(int year, int month) { return String.format("%s:%s", year, month); }
From source file:Main.java
public static String FormatElement(String name, String value) { return String.format("<%1$s>%2$s</%1$s>\n", name, value); }
From source file:Main.java
public static float b2mb(int b) { String mb = String.format(Locale.getDefault(), "%.2f", (float) b / 1024 / 1024); return Float.valueOf(mb); }
From source file:Main.java
public static String getSessionKey(String sessionId, int sessionType) { return String.format("%s_%d", sessionId, sessionType); }
From source file:Main.java
public static String makeIntentExtraName(Class<?> cls, String extraName) { return String.format("%s.EXTRA_%s", cls.getSimpleName(), extraName.toUpperCase()); }
From source file:Main.java
public static String makeIntentActionName(Class<?> cls, String actionName) { return String.format("%s.action.%s", cls.getName(), actionName.toUpperCase()); }