优化MD5性能

This commit is contained in:
Looly
2023-05-04 03:14:03 +08:00
parent 6607b3ab6e
commit 47ab0d02c3
4 changed files with 47 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
package org.dromara.hutool.crypto.digest;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.thread.ConcurrencyTester;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -17,4 +19,26 @@ public class Md5Test {
Assertions.assertEquals(16, hex16.length());
Assertions.assertEquals("cb143acd6c929826", hex16);
}
@Test
void md5ThreadSafeTest() {
final String text = "Hutool md5 test str";
final ConcurrencyTester tester = new ConcurrencyTester(1000);
tester.test(()->{
final String digest = MD5.of().digestHex(text);
Assertions.assertEquals("8060075dd8df47bac3247438e940a728", digest);
});
IoUtil.closeQuietly(tester);
}
@Test
void md5ThreadSafeTest2() {
final String text = "Hutool md5 test str";
final ConcurrencyTester tester = new ConcurrencyTester(1000);
tester.test(()->{
final String digest = new Digester("MD5").digestHex(text);
Assertions.assertEquals("8060075dd8df47bac3247438e940a728", digest);
});
IoUtil.closeQuietly(tester);
}
}