133tosakarin commented on PR #1142:
URL: https://github.com/apache/ratis/pull/1142#issuecomment-2339746397

   private String randomString(int length) {
           StringBuilder sb = new StringBuilder();
           for (int i = 0; i < length; i++) {
               sb.append((char) (Math.random() * 26 + 'a'));
           }
           return sb.toString();
       }
   
       @Benchmark
       public void md5Test(Blackhole blackhole) throws NoSuchAlgorithmException 
{
           int length = 1000;
           md5 = MessageDigest.getInstance("MD5");
           for (int i = 0; i < 1000; ++i) {
               md5.reset();
               md5.update(randomString(length).getBytes());
               blackhole.consume(md5.digest());
               length += 100;
           }
       }
   
       @Benchmark
       public void md5Test2(Blackhole blackhole) throws 
NoSuchAlgorithmException {
           int length = 10000;
           for (int i = 0; i < 1000; ++i) {
               MessageDigest md5 = MessageDigest.getInstance("MD5");
               md5.reset();
               md5.update(randomString(length).getBytes());
               blackhole.consume(md5.digest());
               length += 100;
           }
   
       }
   
       @Benchmark
       public void md5DoNothingTest() throws NoSuchAlgorithmException {
           MessageDigest md5 = MessageDigest.getInstance("MD5");
           for (int i = 0; i < 1000000; ++i) {
               md5.reset();
           }
       }
   
       @Benchmark
       public void md5DoNothingTest2() throws NoSuchAlgorithmException {
           for (int i = 0; i < 1000000; ++i) {
               MessageDigest md5 = MessageDigest.getInstance("MD5");
               md5.reset();
           }
       }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to