Why does outputting "B" in Java work much slower than outputting "#"?
Hello everyone! I'm a beginner in Java and writing a simple script to build a histogram of random number distribution. In a loop, I output characters to the console via System.out.print(). I noticed a strange thing: when I output the "#" character (hash), the program runs very fast. But if I change the character to "B" (uppercase Latin letter), the execution becomes noticeably slower — a difference of 2-3 times!
Here's simplified code that demonstrates the problem:
```java
public class TestPrint {
public static void main(String[] args) {
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
System.out.print("#"); // or "B"
}
long end = System.currentTimeMillis();
System.out.println("\nTime: " + (end - start) + " ms");
}
```
No answers yet.
Log in to leave an answer