---
title: "Why is printing “B” dramatically slower than printing “#”?"  
description: "Why is printing “B” dramatically slower than printing “#”?"  
author: "Anonymous User"  
published: 2015-05-04  
updated: 2015-05-05  
canonical: https://www.mindstick.com/forum/23186/why-is-printing-b-dramatically-slower-than-printing  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# Why is printing “B” dramatically slower than printing “#”?

First [Matrix](https://www.mindstick.com/forum/2412/how-to-convert-matrix-to-uiimage): O and #.[Second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) Matrix: O and B.\
Using the following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), the first matrix took 8.52 seconds to complete:

```
Random r = new Random();for (int i = 0; i < 1000; i++) {    for (int j = 0; j < 1000; j++) {        if(r.nextInt(4) == 0) {            System.out.print("O");        } else {            System.out.print("#");        }    }   System.out.println(""); }
```

With this code, the second matrix took 259.152 seconds to complete:

```
Random r = new Random();for (int i = 0; i < 1000; i++) {    for (int j = 0; j < 1000; j++) {        if(r.nextInt(4) == 0) {            System.out.print("O");        } else {            System.out.print("B"); //only line changed        }    }    System.out.println("");}
```

What is the reason behind the dramatically different run times?\
As suggested in the [comments](https://www.mindstick.com/news/2328/deadline-for-comments-on-the-draught-indian-telecommunication-bill-is-extended-by-the-dot), [printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy) only System.out.print("#"); takes 7.8871 seconds, whereas System.out.print("B"); gives still printing....\
As [others](https://answers.mindstick.com/qa/33516/what-is-dependency-injection-do-you-use-any-di-library-in-your-project-can-you-name-a-few-of-them-and-why-one-is-better-than-others) who pointed out that it works for them normally, I tried Ideone.com for [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance), and both pieces of code [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) at the same speed.\
Test Conditions:\
I ran this test from Netbeans 7.2, with the [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) into its [console](https://www.mindstick.com/blog/210/the-console-class)I used System.nanoTime() for measurements

## Replies

### Reply by Anonymous User

Pure speculation is that you're using a terminal that attempts to do [word-wrapping](http://en.wikipedia.org/wiki/Word_wrap) rather than character-wrapping, and treats B as a word character but # as a non-word character. So when it reaches the end of a line and searches for a place to break the line, it sees a # almost immediately and happily breaks there; whereas with the B, it has to keep searching for longer, and may have more text to wrap (which may be expensive on some terminals, e.g., outputting backspaces, then outputting spaces to overwrite the letters being wrapped).


---

Original Source: https://www.mindstick.com/forum/23186/why-is-printing-b-dramatically-slower-than-printing

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
