Why printing the character 'B' in a Java loop is much slower than printing the character '#'
Hello colleagues! I'm a beginner Java developer and I've encountered a very strange issue when testing loop performance.
I wrote a simple code that prints 1000 characters to the console. First I used the '#' character, and everything worked fast. Then I replaced '#' with 'B' — and the execution speed dropped several times! Here's my code:
```java
public class PrintTest {
public static void main(String[] args) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
System.out.print("B");
}
long end = System.currentTimeMillis();
System.out.println("\nTime: " + (end - start) + " ms");
start = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
System.out.prin
No answers yet.
Log in to leave an answer