コード例 #1
0
 private void hash(CachedUrlSet set, MessageDigest dig, boolean namesOnly) throws IOException {
   CachedUrlSetHasher hasher = null;
   if (namesOnly) {
     hasher = set.getNameHasher(dig);
   } else {
     hasher = set.getContentHasher(dig);
   }
   int bytesHashed = 0;
   long timeTaken = System.currentTimeMillis();
   while (!hasher.finished()) {
     bytesHashed += hasher.hashStep(256);
   }
   timeTaken = System.currentTimeMillis() - timeTaken;
   if ((timeTaken > 0) && (bytesHashed > 500)) {
     System.out.println("Bytes hashed: " + bytesHashed);
     System.out.println("Time taken: " + timeTaken + "ms");
     System.out.println("Bytes/sec: " + (bytesHashed * 1000 / timeTaken));
   } else {
     System.out.println("No time taken, or insufficient bytes hashed.");
     System.out.println("Bytes hashed: " + bytesHashed);
     System.out.println("Time taken: " + timeTaken + "ms");
   }
 }
コード例 #2
0
 private void measureHashSpeed(SimulatedArchivalUnit sau) throws Exception {
   MessageDigest dig = null;
   try {
     dig = MessageDigest.getInstance("SHA-1");
   } catch (NoSuchAlgorithmException ex) {
     fail("No algorithm.");
   }
   CachedUrlSet set = sau.getAuCachedUrlSet();
   CachedUrlSetHasher hasher = set.getContentHasher(dig);
   SystemMetrics metrics = theDaemon.getSystemMetrics();
   int estimate = metrics.getBytesPerMsHashEstimate(hasher, dig);
   // should be protected against this being zero by MyMockSystemMetrics,
   // but otherwise use the proper calculation.  This avoids test failure
   // due to really slow machines
   assertTrue(estimate > 0);
   long estimatedTime = set.estimatedHashDuration();
   long size = ((Long) PrivilegedAccessor.getValue(set, "totalNodeSize")).longValue();
   assertTrue(size > 0);
   System.out.println("b/ms: " + estimate);
   System.out.println("size: " + size);
   System.out.println("estimate: " + estimatedTime);
   assertEquals(estimatedTime, theDaemon.getHashService().padHashEstimate(size / estimate));
 }