List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBStoreTransaction.java
public DynamoDBStoreTransaction(BaseTransactionConfig config) { super(config); id = Constants.HEX_PREFIX + Long.toHexString(System.nanoTime()); LOG.debug("begin id:{} config:{}", id, config); }
From source file:copter.HCSR04.java
private float getDistance(GpioPinDigitalOutput pinTrig, GpioPinDigitalInput pinEcho) { float result = 0.0F; trigger(pinTrig);//from w w w . j a va 2s . co m if (!echoHigh(pinEcho)) { return -1; } long start = System.nanoTime(); if (!echoLow(pinEcho)) { return -1; } long end = System.nanoTime(); long pulse = end - start; result = pulse / 1_000_000_000F; result = result * soundSpeed / 2; return result; }
From source file:com.xuggle.xuggler.ConverterExhaustiveTest.java
/** * This test makes sure that real-time writing of data works; this * MUST run at least longer than the file in question, so use a short * file for testing./*w ww .j a v a 2 s.com*/ * @throws ParseException */ public void testRealTimeConversion() throws ParseException { String[] args = new String[] { "--containerformat", "mov", "--acodec", "libmp3lame", "--asamplerate", "22050", "--achannels", "2", "--abitrate", "64000", "--aquality", "0", "--vcodec", "mpeg4", "--vscalefactor", "1.0", "--vbitrate", "300000", "--vbitratetolerance", "12000000", "--vquality", "0", "--realtime", "fixtures/testfile_videoonly_20sec.flv", this.getClass().getName() + "_" + this.getName() + ".mov" }; converter = new Converter(); Options options = converter.defineOptions(); CommandLine cmdLine = converter.parseOptions(options, args); assertTrue("all commandline options successful", cmdLine != null); final long startTime = System.nanoTime(); converter.run(cmdLine); final long endTime = System.nanoTime(); final long delta = endTime - startTime; // 20 second test file; assertTrue("did not take long enough", delta >= 18L * 1000 * 1000 * 1000); assertTrue("took too long", delta <= 60L * 1000 * 1000 * 1000); }
From source file:com.ideabase.repository.core.service.HashMapStateManagerImpl.java
public String generateRequestStateToken() { final StringBuilder builder = new StringBuilder(); builder.append(mPrefix).append(System.nanoTime()).append(Math.random() * 100).append(mSuffix); return DigestUtils.shaHex(builder.toString()); }
From source file:gridool.util.GridUtils.java
@Nonnull public static String generateJobId(@Nonnull String localNodeId, @Nonnull GridJob job) { final long time = System.nanoTime(); final int hashcode = System.identityHashCode(job); long tid = Thread.currentThread().getId(); return localNodeId + '#' + Long.toString(time) + '/' + Integer.toString(hashcode) + 'T' + Long.toString(tid); }
From source file:org.jinos.transport.HttpTransport.java
/** * Call the service// ww w . ja v a 2 s.c o m * * @param <T> The return type * @param envelope The request envelope * @param resultClass The class of the result in the response * @param httpHeaders The custom Http headers * @return The response * @throws Exception An exception */ public <T> T call(String reqXMLString, Class<T> resultClass, Map<String, String> httpHeaders) throws Exception { try { long start = System.nanoTime(); HttpPost post = new HttpPost(this.getUrl()); post.setEntity(new StringEntity(reqXMLString)); post.setHeader("Content-type", "text/xml; charset=UTF-8"); if (httpHeaders != null) { for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { post.setHeader(entry.getKey(), entry.getValue()); } } /* if (this.getUsername() != null && this.getPassword() != null) { post.addHeader("Authorization", "Basic " + Base64Encoder.encodeString(this.getUsername() + ":" + this.getPassword())); }*/ HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 6000); /* if (this.isDEBUG()) { Log.i(this.getClass().getSimpleName(), "Request: " + envelope.toString()); }*/ HttpClient client = new DefaultHttpClient(httpParameters); HttpResponse response = client.execute(post); int status = response.getStatusLine().getStatusCode(); Log.i(this.getClass().getSimpleName(), "The server has been replied. " + ((System.nanoTime() - start) / 1000) + "us, status is " + status); start = System.nanoTime(); InputStream is = response.getEntity().getContent(); if (true) { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) { sb.append(line); sb.append("\n"); } Log.i(this.getClass().getSimpleName(), "Response: " + sb.toString()); br.close(); isr.close(); is.close(); is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8")); Log.i(this.getClass().getSimpleName(), "DEBUG mode delay: " + ((System.nanoTime() - start) / 1000) + "us"); start = System.nanoTime(); } /* GenericHandler handler = new GenericHandler(resultClass, this.isDEBUG()); if (status == 200) { handler.parseWithPullParser(is); } else { throw new Exception("Can't parse the response, status: " + status); } Log.i(this.getClass().getSimpleName(), "The reply has been parsed: " + ((System.nanoTime() - start) / 1000) + "us"); */ //return (T) handler.getObject(); return null; } catch (Exception e) { Log.e(this.getClass().getSimpleName(), e.toString(), e); throw e; } }
From source file:com.hazelcast.simulator.worker.metronome.SleepingMetronome.java
@Override public long waitForNext() { // set random interval on the first run if (nextNanos == 0) { nextNanos = nanoTime() + nextLong(0, intervalNanos); }/*from w ww .j av a 2s .c o m*/ long now; while ((now = System.nanoTime()) < nextNanos) { LockSupport.parkNanos(nextNanos - now); } long expectedStartNanos = nextNanos; nextNanos += intervalNanos; return accountForCoordinatedOmission ? expectedStartNanos : nanoTime(); }
From source file:br.upe.ecomp.doss.algorithm.volitiveapso.WeightedAPSOParticle.java
/** * Updates the current position of the particle and the fitness variation. * //from www . j a v a 2 s. c o m * @param problem The problem that we are trying to solve. */ public void updateCurrentPosition(Problem problem) { MersenneTwister random = new MersenneTwister(System.nanoTime()); double[] position = getCurrentPosition(); double[] nextPosition = new double[getDimensions()]; double newPosition; for (int i = 0; i < getDimensions(); i++) { newPosition = position[i] + getVelocity()[i]; // if a particle exceeds the search space limit, so inverts the particle velocity on // that dimension which the search space limit was exceeded if (newPosition >= problem.getUpperBound(i)) { position[i] = problem.getUpperBound(i) - getVelocity()[i] * random.nextDouble(); } else if (newPosition <= problem.getLowerBound(i)) { position[i] = problem.getLowerBound(i) - getVelocity()[i] * random.nextDouble(); } else { position[i] = newPosition; } nextPosition[i] = position[i]; } deltaFitness = problem.getFitness(nextPosition) - getCurrentFitness(); if (problem.isFitnessBetterThan(getCurrentFitness(), problem.getFitness(nextPosition)) && deltaFitness < 0) { deltaFitness *= -1; } // The particle never reduces its weight if (!problem.isFitnessBetterThan(getCurrentFitness(), problem.getFitness(nextPosition))) { deltaFitness = 0; } previousPosition = getCurrentPosition().clone(); updateCurrentPosition(nextPosition, problem.getFitness(nextPosition)); if (problem.isFitnessBetterThan(getBestFitness(), getCurrentFitness())) { updateBestPosition(getCurrentPosition(), getCurrentFitness()); } }
From source file:com.disney.opa.fhb.util.FacilityUtil.java
/** * This method is to get relative file path on server * /*from w ww . j a v a 2s . c om*/ * @param document * @return relate file path * @throws Exception */ public String getFacilityDocumentFileNameOnServer(Document document) throws Exception { String fileNameOnServer = File.separator + document.getLicenseeId(); if (document.getDocumentType() != FHBConstants.DOC_TYPE_RECALL_PLAN) { fileNameOnServer += File.separator + document.getFacilityId() + File.separator + document.getDocumentType(); } String newFileName = String .valueOf(document.getDocumentId() != null ? document.getDocumentId() : System.nanoTime()); String fileExt = attachmentUtils.getFileExtension(document.getFileName()); if (StringUtils.isNotEmpty(fileExt)) { newFileName += "." + fileExt; } fileNameOnServer += File.separator + newFileName; return fileNameOnServer; }
From source file:com.github.joulupunikki.math.random.XorShift1024Star.java
/** */ public XorShift1024Star() { init(); this.s = new long[STATE_WORDS]; setSeed(System.nanoTime()); }