# Bug? print() to console slows sketch down

**URL:** <https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044>\
**Category:** Processing\
**Created:** [April 7, 2019, 10:09am UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044 "2019-04-07T10:09:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 7, 2019, 10:09am UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/1 "2019-04-07T10:09:31Z")

</div>

I’m doing a lot of printing to console and for sure it’s obvs not really that necessary beyond debugging. I was very surprised to find out that it was slowing a sketch down _enormously_! Perhaps that’s my naivety but it seems like a bug?

Are there any general resources for a processing noob regarding sketch optimisation?

Many thanks!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 7, 2019, 10:35am UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/2 "2019-04-07T10:35:22Z")

</div>

I think println is slow but also buggy

when you print a lot it might crash your sketch

So really don’t use it, only for debugging of course

To produce text, better use saveStrings - see reference

---

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 7, 2019, 11:27am UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/3 "2019-04-07T11:27:07Z")

</div>

Thanks Chrisir 🙂

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [April 7, 2019, 4:44pm UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/4 "2019-04-07T16:44:31Z")

</div>

Yeah, print statements are slow. Google “system.out.println slow” for an explanation about why.

One thing you can do is limit how often you’re printing. For example you might only print once per second instead of every frame:

```auto
void draw(){
  if(frameCount % 60 == 0){
    println("hello");
  }
}

```

---

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 7, 2019, 5:41pm UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/5 "2019-04-07T17:41:37Z")

</div>

Well - bugger me! Thanks Kevin. Curious stuff.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 9, 2019, 7:13pm UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/6 "2019-04-09T19:13:31Z")

</div>

> [@lnp](#):
>
> Are there any general resources for a processing noob regarding sketch optimisation?

No – it would be nice, although optimisation / optimization tends to depend a lot on what you are doing. For example, 1) printing to the console can be slow 2) the first call to text() can cause lag, on that frame only 3) there are memory efficient ways of dealing with frame buffers if you are trying to time-delay video … and if you are doing trig, it helps to pre-compute expensive parts that you re-use many times… but, in general, there are so many different ways to optimize that it depends a lot on what kind of sketch it is.

So, just ask for help on individual optimization tasks. Many of them people have seen before. If you really want to get deep into it, I would recommend a general survey of the underlying language features (in this case, Java) such as:

> **[O'Reilly Media - Technology and Business Training](https://www.oreilly.com)**
>
> Gain technology and business knowledge and hone your skills with learning resources created and curated by O'Reilly's experts: live online training, video, books, our platform has content from 200+ of the world's best publishers.

---

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 10, 2019, 6:14pm UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/7 "2019-04-10T18:14:55Z")

</div>

Hey Jeremy —

Thanks for taking the time to respond. I’m self taught from a very young age so have lots of sloppy processes in me. My question was always: “but does it float?” I never much cared for efficiency till recently. I have started also to admire the aesthetics of elegant code as much as benefits in performance.

Thanks again for your reply. I’ll surely ask more questions 🙂

LNP

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 11, 2019, 4:25am UTC](https://discourse.processing.org/t/bug-print-to-console-slows-sketch-down/10044/8 "2019-04-11T04:25:42Z")

</div>

Great! Many here are self-taught, in whole or in part, and we are all still learning. When working on a project basis, optimization tends to become more interesting once it is needed (which often seems the right way to prioritize it). Some design patterns and best practices come with time and experience.

> [@lnp](#):
>
> I’ll surely ask more questions

Looking forward to them!
