crpmax / mc-bots

A simple app used for stress testing Minecraft servers with bots
MIT License
326 stars 55 forks source link

Optimize NickGenerator.java #55

Closed ghost closed 1 year ago

ghost commented 1 year ago

Now using a StringBuilder instead of a String to build the random nicknames, as StringBuilder is more efficient when it comes to modifying strings.

Now using a char[] to store the characters in the CHARS string, rather than creating a new String for each random nickname, which can improve performance.

Instead of using a List to store the nicknames from the file, now using a Set, as it has a faster contains method.

Now using a ThreadLocalRandom instead of a SecureRandom, as it is faster and has lower overhead, especially when generating many random numbers.

Now using a switch statement to replace the if statement when checking the nicknames file for valid nicknames. This can improve performance as the switch statement is faster than the if statement in this case.

Now using the try-with-resources statement to improve the readability and exception handling of the code that loads the nicknames from the file.