Skip to content

Instantly share code, notes, and snippets.

@xiaoshuai
Created May 10, 2017 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaoshuai/e934ab415c23f895c35cdf42a6006d90 to your computer and use it in GitHub Desktop.
Save xiaoshuai/e934ab415c23f895c35cdf42a6006d90 to your computer and use it in GitHub Desktop.
public class CompareJavaBase64Util {
public static void main(String[] args) {
String str_1 = "abcABC123+-*/";
String str_2 = "YWJjQUJDMTIzKy0qLw==";
long l_1 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
String encode_str_jdk = java.util.Base64.getEncoder().encodeToString(str_1.getBytes());
byte[] decode_byte_jdk = java.util.Base64.getDecoder().decode(str_2);
// System.out.println(encode_str_jdk);
// System.out.println(new String(decode_byte_jdk));
}
long l_2 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
String encode_str_guava = com.google.common.io.BaseEncoding.base64().encode(str_1.getBytes());
byte[] decode_byte_guava = com.google.common.io.BaseEncoding.base64().decode(str_2);
//System.out.println(encode_str_guava);
//System.out.println(new String(decode_byte_guava));
}
long l_3 = System.currentTimeMillis();
// java.util.Base64: 48 39 47
System.out.println("java.util.Base64: " + (l_2 - l_1));
// BaseEncoding.base64: 105 123 203
System.out.println("com.google.common.io.BaseEncoding: " + (l_3 - l_2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment