# Code running very slow - New to cinder / c++

**URL:** <https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058>\
**Category:** Using Cinder\
**Created:** [February 18, 2018, 4:29pm UTC](https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058 "2018-02-18T16:29:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kobebacon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/kobebacon/32/528_2.png) [@kobebacon](https://discourse.libcinder.org/u/kobebacon)\
**Post date:** [February 18, 2018, 4:29pm UTC](https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058/1 "2018-02-18T16:29:16Z")

</div>

Hi everybody, this is my first post on these forums. I’m new to cpp, cinder and using xcode as an ide so theres a big possibility that my code is inefficient.

I was following the out of date tutorial posted on this site and got to the end of chapter 2 but noticed my application was running super slow (~10sec/frame) 40% cpu usage on computer. I know game engines can render millions of particles at a decent frame rate so I was wondering if anybody could point out a bottleneck or give me some insight on how to find cpu usage bottle necks in my code.

Below are links to the tutorial I followed and some links to the important parts of my code.

tutorial:  
[https://libcinder.org/docs/guides/tour/hello\_cinder\_chapter2.html](https://libcinder.org/docs/guides/tour/hello_cinder_chapter2.html)

code:

> **[RoryShively/opengl-cinder-test](https://github.com/RoryShively/opengl-cinder-test/tree/step1/tiger)**
>
> A test project created so I can practice creating a cinder application - RoryShively/opengl-cinder-test

**The coder is organized in a weird way right now, I figured Id learn cpp first and then figure out how to appropriately structure the code**

Main file:

> <https://github.com/RoryShively/opengl-cinder-test/blob/step1/tiger/src/TestAppApp.cpp>

Headers (contain Particle and ParticleController classes):

> <https://github.com/RoryShively/opengl-cinder-test/blob/step1/tiger/xcode/Particle.h>

  

> <https://github.com/RoryShively/opengl-cinder-test/blob/step1/tiger/xcode/ParticleController.h>

---

<div class="post-metadata">

**Author:** ![kobebacon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/kobebacon/32/528_2.png) [@kobebacon](https://discourse.libcinder.org/u/kobebacon)\
**Post date:** [February 18, 2018, 5:21pm UTC](https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058/2 "2018-02-18T17:21:27Z")

</div>

After running time profiler in xcode I’m seeing that the application is spending 88.8% of its time running cinder::gl::drawSolidCircle

Is this function so slow that it takes roughly 9s to execute about 5000 times?? Has anybody found a good way to speed this up? I was hoping to be able and project this image at a much higher resolution while also making it interactive. I’m not sure if that goal seems reasonable at this point if I continue at the performance I’m at.

**Edit: Is the answer perhaps that cinder::gl::drawSolidCircle is a convenience method and it would be more efficient to run a batch method instead??**

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [February 18, 2018, 5:52pm UTC](https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058/3 "2018-02-18T17:52:49Z")

</div>

Hi,

Yes, an instanced batch rendering of a circle would be one of the ways to do it more efficiently.

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [February 18, 2018, 8:53pm UTC](https://discourse.libcinder.org/t/code-running-very-slow-new-to-cinder-c/1058/4 "2018-02-18T20:53:08Z")

</div>

Yes, `gl::drawSolidCircle` is a convenience method not meant to be fast. In older versions of Cinder (prior to v0.9.0) this method used to be much faster, most notably because the OpenGL driver was able to optimize the code under the hood.

Creating a `gl::VboMesh` from a `geom::Circle` and reusing it would already be faster. Alternatively, you could render a quad combined with a shader like [this one](https://www.shadertoy.com/view/Mll3D4). This, too, can be done by combining a `gl::VboMesh` and a `gl::GlslProg` into a `gl::Batch`. If you want to render more than a few circles, use instanced rendering. All of this is (slightly) more advanced than beginner-level, so don’t lose hope if it proves a bit difficult.

-Paul
