Created
August 26, 2012 11:23
-
-
Save erdbeerschnitzel/3477712 to your computer and use it in GitHub Desktop.
Java MD5 Performance Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.UnsupportedEncodingException; | |
import java.security.*; | |
public class md5 { | |
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException{ | |
for(int a = 0; a < 10; a++){ | |
long creationDate = System.currentTimeMillis(); | |
for(int i = 0; i< 100000; i++){ | |
byte[] bytesOfMessage = ("This is Dart!" + i).getBytes("UTF-8"); | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
byte[] thedigest = md.digest(bytesOfMessage); | |
StringBuffer sb = new StringBuffer(); | |
// can be removed | |
for (int ii = 0; ii< thedigest.length; ++ii) { | |
sb.append(Integer.toHexString((thedigest[ii] & 0xFF) | 0x100).substring(1,3)); | |
} | |
//System.out.println(sb.toString()); | |
} | |
System.out.println(System.currentTimeMillis() - creationDate); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This happened to pop up through Google, so just a small warning: this spends more time in
toHexString
than indigest
.