# Why is square(x, y, 1) so much faster than point(x, y)?

**URL:** https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448
**Category:** Processing
**Created:** [December 10, 2024, 9:24pm UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448 "2024-12-10T21:24:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DevaPan](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DevaPan](https://discourse.processing.org/u/DevaPan)
#### Post date: [December 10, 2024, 9:24pm UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448/1 "2024-12-10T21:24:42Z")

</div>

Anyone knows? I’ve found about it by accident and it doesn’t make much sense to me.

Details:  
stroke(someColor); point(x, y);  
vs.  
noStroke(); fill(someColor); square(x, y, 1);

- the second one is consistently about 3-4 times faster than the 1st
- rect(x, y, 1, 1) can be used instead of square
- the usage of e.g. circle(x, y, 1) will not lead to speed improvement
- it doesn’t work without noStroke()
- default renderer used, but I think it works on all the others (needs more testing)
- tested on Processing 4.2

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [December 10, 2024, 9:54pm UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448/2 "2024-12-10T21:54:10Z")

</div>

Not sure about Java mode because that uses Java AWT to draw graphics but in P2D and P3D the underlying renderer is OpenGL.

Now OpenGL is optimized to draw render images using triangles and is much slower rendering lines so rendering any shape with a `stroke` will be significantly slower than a shape with `noStroke`.

I am not sure about `circle` because OpenGl can represent circles and ellipses as a series of connected triangles (TRIANGLE\_FAN) but I don’t know how Processing implements `circle` and `ellipse`.

For speed avoid using `stroke` whenever possible.

---

<div class="post-metadata">

### Author: ![DevaPan](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DevaPan](https://discourse.processing.org/u/DevaPan)
#### Post date: [December 11, 2024, 5:52pm UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448/3 "2024-12-11T17:52:28Z")

</div>

Thanks.  
I’ve begun replacing point() with square() in my sketches wherever possible and needed, the gain in speed is huge.  
I’ve tried the same with Processing for Android, it’s still faster but barely.

---

<div class="post-metadata">

### Author: ![hx2A](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hx2a/32/14322_2.png) [@hx2A](https://discourse.processing.org/u/hx2A)
#### Post date: [December 13, 2024, 5:06am UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448/4 "2024-12-13T05:06:24Z")

</div>

I know why.

It’s because the point is not really a “point”. It’s a small mesh that is oriented to face the camera.

If you are drawing square points, the mesh is a quad, or two triangles. If you are drawing round points, the mesh is a set of triangles that share one vertex.

When Processing (P2D or P3D) draws a square point, it is the same number of triangles as when it draws a quad (rectangle). When it draws a round point, it is about the same number of triangles as a circle.

There are other details that can affect performance, such as when you use `beginShape(POINTS)` and repeatedly call `vertex()` vs calling `point()` repeatedly. These issues are secondary to the above issue though.

The downside of using `square(x, y, 1)` is that you have to make sure the squares are oriented towards the camera. If you look at the square from a shallow angle, you won’t see anything.

If you need round points and also need performance, you can draw square points but then use a shader to make them look round.

---

<div class="post-metadata">

### Author: ![DevaPan](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DevaPan](https://discourse.processing.org/u/DevaPan)
#### Post date: [December 13, 2024, 1:59pm UTC](https://discourse.processing.org/t/why-is-square-x-y-1-so-much-faster-than-point-x-y/45448/5 "2024-12-13T13:59:24Z")

</div>

Thanks for clearing some things up.  
There is also a related discussion here:

> [@Rect(x,y,1,1); VS. point(x,y);](https://discourse.processing.org/t/rect-x-y-1-1-vs-point-x-y/13299):
>
> Can you guys try this? (try changing the size() on your computers) boolean rectOrPoint; void setup() { size(600, 300); //play with these: make those bigger if you've got a fast modern computer rectOrPoint = false; println(rectOrPoint ? "rect(x, y, 1, 1);" : "point(x, y);"); } void draw() { for (int j=0; j\<height; j++) { for (int i=0; i\<width; i++) { if (rectOrPoint) { fill(random(255), random(255), random(255)); noStroke(); rect(i, j, 1, 1); } …
