public double saveBinaryFileWithBuffer() { double time = System.nanoTime(); File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithBuffer.bin"); DataOutputStream outPut = null; DataInputStream inPut = null; FileOutputStream fileOut = null; FileInputStream fileIn = null; BufferedInputStream buffInput = null; BufferedOutputStream buffOut = null; try { fileOut = new FileOutputStream(file); buffOut = new BufferedOutputStream(fileOut); outPut = new DataOutputStream(buffOut); for (Edge e : edges) { outPut.writeDouble(e.X1); outPut.writeDouble(e.Y1); outPut.writeDouble(e.X2); outPut.writeDouble(e.Y2); outPut.writeDouble(e.color.getRed()); outPut.writeDouble(e.color.getGreen()); outPut.writeDouble(e.color.getBlue()); outPut.flush(); } outPut.close(); } catch (Exception ex) { ex.printStackTrace(); } edges.clear(); // Now read every edge from the file and draw it. try { fileIn = new FileInputStream(file); buffInput = new BufferedInputStream(fileIn); inPut = new DataInputStream(buffInput); if (inPut.available() > 0) { while (inPut.available() > 0) { double X1 = inPut.readDouble(); double Y1 = inPut.readDouble(); double X2 = inPut.readDouble(); double Y2 = inPut.readDouble(); double red = inPut.readDouble(); double green = inPut.readDouble(); double blue = inPut.readDouble(); Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1)); drawEdge(e); } } } catch (Exception ex) { ex.printStackTrace(); } return System.nanoTime() - time; }
private String createUniqueFilename(String path) { String random = "" + System.nanoTime(); // just use the last 16 numbers if (random.length() > 16) random = random.substring(random.length() - 16); random += "" + new Random(System.currentTimeMillis()).nextInt(10000); return path + "\\DELETE_ME_" + random; }
public static void waitUntil(long delayTo) { delayTo = delayTo + System.nanoTime(); long currentT = 0; do { currentT = System.nanoTime(); } while (delayTo >= currentT); }
public static void main(String[] args) { InputStream in = null; OutputStream out = null; try { // byte[] data = new byte[] {1, 2, 3}; int readBuffer = -1; in = new FileInputStream("overview.txt"); out = new FileOutputStream("testdate2.dat"); long startTime = System.nanoTime(); while ((readBuffer = in.read()) != -1) { out.write(readBuffer); } long endTime = System.nanoTime(); System.out.println("Elapsed time is :" + (endTime - startTime)); } catch (Exception ex) { ex.printStackTrace(); } finally { try { out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } }
public void run() { long beginLoopTime; long endLoopTime; long currentUpdateTime = System.nanoTime(); long lastUpdateTime; long deltaLoop; while (running) { beginLoopTime = System.nanoTime(); lastUpdateTime = currentUpdateTime; currentUpdateTime = System.nanoTime(); update((int) ((currentUpdateTime - lastUpdateTime) / (1000 * 1000))); render(); endLoopTime = System.nanoTime(); deltaLoop = endLoopTime - beginLoopTime; if (deltaLoop > desiredDeltaLoop) { // Do nothing. We are already late. } else { try { Thread.sleep((desiredDeltaLoop - deltaLoop) / (1000 * 1000)); } catch (InterruptedException e) { // Do nothing } } } }
/** * Main method. * * @param args command-line arguments */ public static void main(final String[] args) { try { // initialize timer final long time = System.nanoTime(); // create session final BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin"); // version 1: perform command and print returned string System.out.println(session.execute("info")); // version 2 (faster): perform command and pass on result to output stream final OutputStream out = System.out; session.execute("xquery 1 to 10", out); // close session session.close(); // print time needed final double ms = (System.nanoTime() - time) / 1000000d; System.out.println("\n\n" + ms + " ms"); } catch (final IOException ex) { // print exception ex.printStackTrace(); } }
TimeStringParsing() throws IOException { String filename = "file:C:\\Documents and Settings\\caron\\.unidata\\cachePersist\\fileD-godas-singleAgg.ncml"; Element aggElem = ucar.nc2.util.xml.Parse.readRootElement(filename); List<Element> ncList = aggElem.getChildren("netcdf", NcMLReader.ncNS); for (Element netcdfElemNested : ncList) { String location = netcdfElemNested.getAttributeValue("location"); List<Element> cacheElemList = netcdfElemNested.getChildren("cache", NcMLReader.ncNS); for (Element cacheElemNested : cacheElemList) { String varName = cacheElemNested.getAttributeValue("varName"); String sdata = cacheElemNested.getText(); System.out.println("text size = " + sdata.length()); long start = System.nanoTime(); String[] vals = sdata.split(" "); double took = .001 * .001 * .001 * (System.nanoTime() - start); System.out.println(" split took = " + took + " sec; "); start = System.nanoTime(); Array data = Array.makeArray(DataType.DOUBLE, vals); took = .001 * .001 * .001 * (System.nanoTime() - start); System.out.println(" makeArray took = " + took + " sec; "); } } }
public Writable call(Class<?> protocol, Writable param, long receivedTime) throws IOException { try { Invocation call = (Invocation) param; if (verbose) log("Call: " + call); Method method = protocol.getMethod(call.getMethodName(), call.getParameterClasses()); method.setAccessible(true); int qTime = (int) (System.currentTimeMillis() - receivedTime); long startNanoTime = System.nanoTime(); Object value = method.invoke(instance, call.getParameters()); long processingMicroTime = (System.nanoTime() - startNanoTime) / 1000; if (LOG.isDebugEnabled()) { LOG.debug( "Served: " + call.getMethodName() + " queueTime (millisec)= " + qTime + " procesingTime (microsec)= " + processingMicroTime); } rpcMetrics.rpcQueueTime.inc(qTime); rpcMetrics.rpcProcessingTime.inc(processingMicroTime); MetricsTimeVaryingRate m = (MetricsTimeVaryingRate) rpcMetrics.registry.get(call.getMethodName()); if (m == null) { try { m = new MetricsTimeVaryingRate(call.getMethodName(), rpcMetrics.registry); } catch (IllegalArgumentException iae) { // the metrics has been registered; re-fetch the handle LOG.debug("Error register " + call.getMethodName(), iae); m = (MetricsTimeVaryingRate) rpcMetrics.registry.get(call.getMethodName()); } } // record call time in microseconds m.inc(processingMicroTime); if (verbose) log("Return: " + value); return new ObjectWritable(method.getReturnType(), value); } catch (InvocationTargetException e) { Throwable target = e.getTargetException(); if (target instanceof IOException) { throw (IOException) target; } else { IOException ioe = new IOException(target.toString()); ioe.setStackTrace(target.getStackTrace()); throw ioe; } } catch (Throwable e) { if (!(e instanceof IOException)) { LOG.error("Unexpected throwable object ", e); } IOException ioe = new IOException(e.toString()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
private double test(StreamTester tester, int numberOfTests) throws IOException { double duration = 0d; for (int i = 0; i < numberOfTests; i++) { long start = System.nanoTime(); tester.doTest(); duration += (double) (System.nanoTime() - start); } return duration / 1.0e9; }
//////// Pivot public double pivotFunction() { long start = System.nanoTime(); myQuick.quickSort(myArray, myArray.length); // Simple quick Sort long finish = System.nanoTime(); double delta = finish - start; return delta; }
//////// Median public double Median(int size) { long start = System.nanoTime(); TextMergeQuick.quickSort(size, myArray, myArray.length); long finish = System.nanoTime(); double delta = finish - start; return delta; }
void process(String logDir) throws IOException { LogReader reader = new LogReader(new AccessLogParser()); long startElapsed = System.nanoTime(); LogReader.Stats stats = new LogReader.Stats(); reader.readAll(new File(logDir), new MyFF(), new MyClosure(), new MyLogFilter(), stats); long elapsedTime = System.nanoTime() - startElapsed; System.out.printf(" total= %d passed=%d%n", stats.total, stats.passed); System.out.printf(" elapsed=%f msecs %n", elapsedTime / (1000 * 1000.0)); }
public static void main(String[] args) { debug = args.length > 0; long start = System.nanoTime(); solve(); out.flush(); long end = System.nanoTime(); dump((end - start) / 1000000 + " ms"); in.close(); out.close(); }
public double saveBinaryFileNoBuffer() throws IOException { double time = System.nanoTime(); File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithoutBuffer.bin"); FileChannel fileChannel = null; MappedByteBuffer map = null; int counter = 0; try { // fileOut = new FileOutputStream(file); // outPut = new DataOutputStream(fileOut); fileChannel = new RandomAccessFile(file, "rw").getChannel(); map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 4096 * 128 * 128); counter = edges.size(); for (Edge e : edges) { map.putDouble(e.X1); map.putDouble(e.Y1); map.putDouble(e.X2); map.putDouble(e.Y2); map.putDouble(e.color.getRed()); map.putDouble(e.color.getGreen()); map.putDouble(e.color.getBlue()); } } catch (Exception ex) { ex.printStackTrace(); } edges.clear(); map.position(0); // Now read every edge from the file and draw it. try { // fileIn = new FileInputStream(file); // inPut = new DataInputStream(fileIn); fileChannel = new RandomAccessFile(file, "r").getChannel(); map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128); for (int i = 0; i <= counter; i++) { double X1 = map.getDouble(); double Y1 = map.getDouble(); double X2 = map.getDouble(); double Y2 = map.getDouble(); double red = map.getDouble(); double green = map.getDouble(); double blue = map.getDouble(); Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1)); drawEdge(e); } } catch (Exception ex) { ex.printStackTrace(); } return System.nanoTime() - time; }
public static void main(String[] args) { Scanner scanner = null; // scanner for input file if (args.length == 1) { try { scanner = new Scanner(new File(args[0])); startTime = System.nanoTime(); while (scanner.hasNext()) { String currWord = scanner.next(); String sortedWord = alphaLowerSort(currWord); ArrayList<String> listAtKey = anagrams.get(sortedWord); if (listAtKey == null) { listAtKey = new ArrayList<String>(); anagrams.put(sortedWord, listAtKey); listAtKey.add(currWord); } else { if (!listAtKey.contains(currWord.toLowerCase())) listAtKey.add(currWord.toLowerCase()); } } endTime = System.nanoTime(); String mostAnagramsKey = null; int mostAnagramsSize = 0; for (Entry<String, ArrayList<String>> entry : anagrams.entrySet()) { System.out.println("Anagram(s) at key \"" + entry.getKey() + "\" : " + entry.getValue()); int numAnagrams = entry.getValue().size(); if (mostAnagramsKey == null) { mostAnagramsKey = entry.getKey(); mostAnagramsSize = entry.getValue().size(); } else if (numAnagrams > anagrams.get(mostAnagramsKey).size()) { mostAnagramsKey = entry.getKey(); mostAnagramsSize = entry.getValue().size(); } } System.out.println("\n-- Runtime Statistics --"); System.out.println("Number of anagram sets: " + anagrams.size()); System.out.println("Algorithm Runtime: " + (endTime - startTime) / 1000000000.0 + "s"); System.out.println("Largest set of anagrams: " + anagrams.get(mostAnagramsKey)); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } } else { System.err.println("Error: Invalid number of args"); System.exit(0); } } // end main()
private static void run(Callable c, boolean read, int size) { // Count all i/o time from here, including all retry overheads long start_io_ms = System.currentTimeMillis(); while (true) { try { long start_ns = System.nanoTime(); // Blocking i/o call timing - without counting repeats c.call(); TimeLine.record_IOclose(start_ns, start_io_ms, read ? 1 : 0, size, Value.HDFS); break; // Explicitly ignore the following exceptions but // fail on the rest IOExceptions } catch (EOFException e) { ignoreAndWait(e, false); } catch (SocketTimeoutException e) { ignoreAndWait(e, false); } catch (S3Exception e) { // Preserve S3Exception before IOException // Since this is tricky code - we are supporting different HDFS version // New version declares S3Exception as IOException // But old versions (0.20.xxx) declares it as RuntimeException // So we have to catch it before IOException !!! ignoreAndWait(e, false); } catch (IOException e) { ignoreAndWait(e, true); } catch (Exception e) { throw Log.errRTExcept(e); } } }
/** run once each game tick */ public void networkTick() { field_72584_h = false; currentTicks++; mcServer.theProfiler.startSection("packetflow"); theNetworkManager.processReadPackets(); mcServer.theProfiler.endStartSection("keepAlive"); if ((long) currentTicks - ticksOfLastKeepAlive > 20L) { ticksOfLastKeepAlive = currentTicks; keepAliveTimeSent = System.nanoTime() / 0xf4240L; keepAliveRandomID = randomGenerator.nextInt(); sendPacketToPlayer(new Packet0KeepAlive(keepAliveRandomID)); } if (chatSpamThresholdCount > 0) { chatSpamThresholdCount--; } if (creativeItemCreationSpamThresholdTally > 0) { creativeItemCreationSpamThresholdTally--; } mcServer.theProfiler.endStartSection("playerTick"); if (!field_72584_h && !playerEntity.playerHasConqueredTheEnd) { playerEntity.onUpdateEntity(); } mcServer.theProfiler.endSection(); }
public PrepartitionSolution(long[] input) { generator = new Random(System.nanoTime()); sequence = input; sol = new int[input.length]; randomizeSolution(); // sol[0] = 0; sol[1] = 1; sol[2] = 1; sol[3] = 3; sol[4] = 4; }
public HashMap<Integer, SpeciesZoneType> processSimJob(SimJob job) throws SQLException, SimulationException { this.setSimJob(job); // init ecosystem data sets EcosystemTimesteps ecosysTimesteps = new EcosystemTimesteps(); Map<Integer, NodeRelationships> ecosysRelationships = new HashMap<>(); NodeTimesteps nodeTimesteps; if (useHDF5 == false) { initOutputStreams(); } int[] nodeListArray = job.getSpeciesNodeList(); List<SpeciesZoneType> speciesZoneList = job.getSpeciesZoneList(); int timesteps = job.getTimesteps(); for (int i = 0; i < nodeListArray.length; i++) { int nodeId = nodeListArray[i]; nodeTimesteps = new NodeTimesteps(nodeId, timesteps); nodeTimesteps.setBiomass(0, speciesZoneList.get(i).getCurrentBiomass()); for (int j = 1; j < timesteps; j++) { nodeTimesteps.setBiomass(j, 0); } ecosysTimesteps.putNodeTimesteps(nodeId, nodeTimesteps); } ConsumeMap consumeMap = new ConsumeMap(job.getSpeciesNodeList(), Constants.ECOSYSTEM_TYPE); PathTable pathTable = new PathTable(consumeMap, job.getSpeciesNodeList(), !PathTable.PP_ONLY); // Log.consoleln("consumeMap " + consumeMap.toString()); // Log.consoleln("pathTable " + pathTable.toString()); status = Constants.STATUS_SUCCESS; job.setConsumeMap(consumeMap); job.setPathTable(pathTable); createEcoSysRelationships(ecosysTimesteps, ecosysRelationships, pathTable.toString()); long start = System.nanoTime(); // generate data for current job HashMap<Integer, SpeciesZoneType> mSpecies = genSpeciesDataset(job, ecosysTimesteps, ecosysRelationships); System.out.printf( "\nTime... %d seconds\n\n", (System.nanoTime() - start) / (long) Math.pow(10, 9)); return mSpecies; }
private static void bytebench(ArrayList<int[]> postings, CompressionMode cm, boolean verbose) { int maxlength = 0; for (int[] x : postings) if (maxlength < x.length) maxlength = x.length; if (verbose) System.out.println("Max array length: " + maxlength); byte[] compbuffer = new byte[6 * (maxlength + 1024)]; int[] decompbuffer = new int[maxlength]; if (verbose) System.out.println("Scheme -- bits/int -- speed (mis)"); for (ByteIntegerCODEC c : (cm == CompressionMode.DELTA ? bcodecs : regbcodecs)) { long bef = 0; long aft = 0; long decomptime = 0; long volumein = 0; long volumeout = 0; byte[][] compdata = new byte[postings.size()][]; for (int k = 0; k < postings.size(); ++k) { int[] in = postings.get(k); IntWrapper inpos = new IntWrapper(0); IntWrapper outpos = new IntWrapper(0); c.compress(in, inpos, in.length, compbuffer, outpos); int clength = outpos.get(); inpos = new IntWrapper(0); outpos = new IntWrapper(0); c.uncompress(compbuffer, inpos, clength, decompbuffer, outpos); volumein += in.length; volumeout += clength; if (outpos.get() != in.length) throw new RuntimeException("bug"); for (int z = 0; z < in.length; ++z) if (in[z] != decompbuffer[z]) throw new RuntimeException("bug"); compdata[k] = Arrays.copyOf(compbuffer, clength); } bef = System.nanoTime(); for (byte[] cin : compdata) { IntWrapper inpos = new IntWrapper(0); IntWrapper outpos = new IntWrapper(0); c.uncompress(cin, inpos, cin.length, decompbuffer, outpos); if (inpos.get() != cin.length) throw new RuntimeException("bug"); } aft = System.nanoTime(); decomptime += (aft - bef); double bitsPerInt = volumeout * 8.0 / volumein; double decompressSpeed = volumein * 1000.0 / (decomptime); if (verbose) System.out.println( c.toString() + "\t" + String.format("\t%1$.2f\t%2$.2f", bitsPerInt, decompressSpeed)); } }
public static void main(String[] args) throws IOException { float minsup = Float.parseFloat(args[0]); float minconf = Float.parseFloat(args[1]); String infile = args[2]; String outfile = args[3]; int option = Integer.parseInt(args[4]); System.out.println( "minsup: " + minsup + " minconf: " + minconf + " infile: " + infile + " outfile: " + outfile); // Create initial projected database long start = 0; long end = 0; long duration = 0; start = System.nanoTime(); HashMap<String, ArrayList<String>> itemSet = createSet(infile, minsup); end = System.nanoTime(); System.out.println("createSet took: " + (end - start) + " nanoseconds"); System.out.println("Size of nulEP: " + nulEP.size()); for (String key : itemSet.keySet()) { Collections.sort(itemSet.get(key)); } // Main function start = System.nanoTime(); System.out.println("TP: " + TP("", itemSet, minsup, 0)); end = System.nanoTime(); System.out.println("TP took: " + (end - start) + " nanoseconds"); // Print frequent itemsets System.out.println("freqItemsets: " + freqItemsets); System.out.println("singleElements: " + singleElements); System.out.println("nulEP: " + nulEP); // Rule generation ruleGen(freqItemsets); }
public PrepartitionSolution(PrepartitionSolution p) { sequence = p.sequence; generator = new Random(System.nanoTime()); sol = new int[p.sol.length]; for (int i = 0; i < sol.length; ++i) { sol[i] = p.sol[i]; } }
void work_helper( NonBlockingIdentityHashMap<String, String> nbhm, String thrd, int d, String[] keys) { final int ITERS = 20000; for (int j = 0; j < 10; j++) { long start = System.nanoTime(); for (int i = d; i < ITERS; i += 2) assertThat( "this key not in there, so putIfAbsent must work", nbhm.putIfAbsent(keys[i], thrd), is((String) null)); for (int i = d; i < ITERS; i += 2) assertTrue(nbhm.remove(keys[i], thrd)); double delta_nanos = System.nanoTime() - start; double delta_secs = delta_nanos / 1000000000.0; double ops = ITERS * 2; // System.out.println("Thrd"+thrd+" "+(ops/delta_secs)+" ops/sec size="+nbhm.size()); } }
/** * Blocks and reads into a <tt>Buffer</tt> from this <tt>PullBufferStream</tt>. * * @param buffer the <tt>Buffer</tt> this <tt>PullBufferStream</tt> is to read into * @throws IOException if an I/O error occurs while this <tt>PullBufferStream</tt> reads into the * specified <tt>Buffer</tt> * @see AbstractVideoPullBufferStream#doRead(Buffer) */ @Override protected void doRead(Buffer buffer) throws IOException { /* * Determine the Format in which we're expected to output. We cannot * rely on the Format always being specified in the Buffer because it is * not its responsibility, the DataSource of this ImageStream knows the * output Format. */ Format format = buffer.getFormat(); if (format == null) { format = getFormat(); if (format != null) buffer.setFormat(format); } if (format instanceof AVFrameFormat) { Object o = buffer.getData(); AVFrame frame; if (o instanceof AVFrame) frame = (AVFrame) o; else { frame = new AVFrame(); buffer.setData(frame); } AVFrameFormat avFrameFormat = (AVFrameFormat) format; Dimension size = avFrameFormat.getSize(); ByteBuffer data = readScreenNative(size); if (data != null) { if (frame.avpicture_fill(data, avFrameFormat) < 0) { data.free(); throw new IOException("avpicture_fill"); } } else { /* * This can happen when we disconnect a monitor from computer * before or during grabbing. */ throw new IOException("Failed to grab screen."); } } else { byte[] bytes = (byte[]) buffer.getData(); Dimension size = ((VideoFormat) format).getSize(); bytes = readScreen(bytes, size); buffer.setData(bytes); buffer.setOffset(0); buffer.setLength(bytes.length); } buffer.setHeader(null); buffer.setTimeStamp(System.nanoTime()); buffer.setSequenceNumber(seqNo); buffer.setFlags(Buffer.FLAG_SYSTEM_TIME | Buffer.FLAG_LIVE_DATA); seqNo++; }
public static void main(String[] args) throws IOException { // long startTime = System.nanoTime(); // readFile("C:/Users/Nitin/Desktop/nitin.txt", 100); // long endTime = System.nanoTime(); // System.out.println("IT took " + (endTime - startTime) + "ns to read"); // String s = "This is a new World"; // byte b[] = s.getBytes(); // writeFile(b, "C:/Users/Nitin/Desktop/nitin.txt", 5); long startTime = System.nanoTime(); efficientCopyFile( "C:/Users/Nitin/Desktop/the-hobbit-the-desolation-of-smaug-yify-english.srt", "C:/Users/Nitin/Desktop/nitin1.txt", 200); long endTime = System.nanoTime(); System.out.println( "It took" + (endTime - startTime) + "ns to read and write it to another file the file"); }
@Override @Nullable Resource getResource(String name, boolean flag) { final long started = myDebugTime ? System.nanoTime() : 0; if (myMemoryLoader != null) { JarMemoryLoader loader = myMemoryLoader.get(); if (loader != null) { Resource resource = loader.getResource(name); if (resource != null) return resource; } } ZipFile file = null; try { file = acquireZipFile(); if (file == null) return null; ZipEntry entry = file.getEntry(name); if (entry != null) { ++hits; if (hits % 1000 == 0 && ClasspathCache.doDebug) { ClasspathCache.LOG.debug("Exists jar loader: misses:" + misses + ", hits:" + hits); } return new MyResource(entry, new URL(getBaseURL(), name)); } if (misses % 1000 == 0 && ClasspathCache.doDebug) { ClasspathCache.LOG.debug("Missed " + name + " from jar:" + myURL); } ++misses; } catch (Exception e) { return null; } finally { try { releaseZipFile(file); } catch (IOException ignored) { } final long doneFor = myDebugTime ? System.nanoTime() - started : 0; if (doneFor > NS_THRESHOLD) { ClasspathCache.LOG.debug(doneFor / 1000000 + " ms for jar loader get resource:" + name); } } return null; }
protected final double _testRawDeser(int reps, byte[] json, ObjectReader reader) throws IOException { long start = System.nanoTime(); final JsonFactory f = reader.getFactory(); while (--reps >= 0) { JsonParser p = f.createParser(new ByteArrayInputStream(json)); JsonToken t; while ((t = p.nextToken()) != null) { if (t == JsonToken.VALUE_STRING) { p.getText(); } else if (t.isNumeric()) { p.getNumberValue(); } ; } p.close(); } hash = f.hashCode(); return _msecsFromNanos(System.nanoTime() - start); }
public static void main(String[] args) { Logger log = LoggerFactory.getLogger(DiscreteFourierTransformer.class); long startTime = System.nanoTime(); Random rand = new Random(); List<Double> vals = new ArrayList<Double>(); for (int i = 0; i < 1000; i++) { vals.add(rand.nextDouble()); } ComplexSample sample = new ComplexSample(vals); ComplexSample result = new DiscreteFourierTransformer().transform(sample); long elapsedTime = System.nanoTime() - startTime; log.info("Elapsed time: " + elapsedTime); }
public static void main(String[] args) throws Throwable { long startTime = System.nanoTime(); if (args.length < 2) { System.out.println("Not enough arguments"); System.exit(1); } String inputFileName = args[args.length - 2]; String outputFileName = args[args.length - 1]; includeNames.add(inputFileName); new File(cacheDirectoryName).mkdir(); BufferedWriter out = new BufferedWriter(new FileWriter(outputFileName)); mainContext = contextFromFilename(inputFileName); processFile(getBufferedReader(inputFileName, mainContext), out, mainContext); out.close(); System.out.println("Elapsed time: " + ((System.nanoTime() - startTime) / 1000000.0f) + " ms."); }
// Binary search. public boolean contains(String word) { int low = 0; int high = words.size() - 1; long time = System.nanoTime(); while (low <= high) { int mid = (low + high) / 2; int diff = words.get(mid).compareTo(word); if (diff == 0) { avgLookupTime = avgLookupTime * (avgIndex - 1) / avgIndex + (System.nanoTime() - time) / avgIndex; avgIndex++; return true; } else if (diff < 0) { low = mid + 1; } else { high = mid - 1; } } return false; }