Friday, September 27, 2019

JAVA AES Performance Testing


Motivation

Want to know the better choice of coding.

Simple Note

Test functions in
TestAESPerformance.java

Also use a simple helper class for performance testing
PerformanceTestHelper.java


Test Cases

100 runs each

1. testCreateInstanceEachTimeCommon: Simple AES with pre-generated key, no salt, create Cipher each time

2. testReuseInstanceCommon: Simple AES with pre-generated key, no salt, reuse Cipher

3. testCreateInstanceEachTimePBK: Use SecretKeyFactory and PBEKeySpec to generate SecretKey with PBKDF2WithHmacSHA256 algorithm, generate key and create Cipher each time

4. testReuseInstancePBK: Use SecretKeyFactory and PBEKeySpec to generate SecretKey with PBKDF2WithHmacSHA256 algorithm, reuse Cipher

Results



Summary

1. Use pre-generated key is much faster
(testCreateInstanceEachTimeCommon is much faster than testCreateInstanceEachTimePBK).

2. Reuse Cipher is much faster.

3. Once the Cipher is created, the speed of Encryption are similar between Common and PBK
(the 90% time of testReuseInstancePBK even faster than testReuseInstanceCommon)

Conclusion

Do not create Cipher each time, try to reuse it.

References

Round double
Round a double to 2 decimal places

List Initial Size (need to get the fastest 90% so...)
Initial size for the ArrayList


No comments:

Post a Comment