# This simple sketch runs much faster on p5.js (60fps) than Processing/Java (5fps)

**URL:** https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300
**Category:** Processing
**Created:** [July 17, 2021, 1:36pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300 "2021-07-17T13:36:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mojinovi](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mojinovi](https://discourse.processing.org/u/mojinovi)
#### Post date: [July 17, 2021, 1:36pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/1 "2021-07-17T13:36:14Z")

</div>

Hello all,  
I’m a total beginner in Processing and casual developper, so sorry if this obvious…  
I’m working on a simple sketch that I initially coded on p5.js and I want now to play it in processing.  
I expected to have a better performance on processing but was surprised it’s not the case.

The code in p5.js is:

```auto
function setup() {
  maxlines=2000;  
  createCanvas(800, 800);
  frameRate(60);
  stroke('rgba(100%,100%,100%,0.1)');
  fill(250)
}

function draw() {
  background(0);
  text(frameRate(), 10, 10);
  for (let i = 0; i < maxlines; i++) {
    line(random(width),random(height),random(width),random(height));
  };
}

```

And in Processing (Java Mode)

```auto
int maxlines=2000;

void setup(){
  size(800,800);
  stroke(250,250,250,50);
  frameRate(60);
}

void draw(){
  background(0);
  text(frameRate, 10, 10);
  for (int i=0;i<maxlines;i=i+1){
    line(random(width), random(height), random(width),random(height));
  }
  
}

```

p5.js printed frame rate keeps close to 60fps whereas in processing, it starts at 60 and goes down quickly to ~5fps

What I’m I missing here? Is it normal behavior?  
Is the problem because of the way I coded it in Java? Or maybe an installation issue?  
Thanks for helping

---

<div class="post-metadata">

### Author: ![TomD](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@TomD](https://discourse.processing.org/u/TomD)
#### Post date: [July 17, 2021, 2:01pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/2 "2021-07-17T14:01:55Z")

</div>

Hi there,  
I’m also pretty new to this but I thought I’d check to see if its an installation issue or not.

Your processing code also runs slowly for me, it is after all drawing 2000 lines and making 4\*2000 random() calls per frame!

frameRate starts high then reduces, I think because it is taking an average over time.

I’m not sure why this behavior would be different in p5, I know very little about javascript…

I don’t think there’s any errors in your processing code, you are just asking it to do a lot!  
Perhaps reduce the number of lines you are drawing or consider ways to reduce the number of function calls you are making to increase framerate?

Hope that helps?

---

<div class="post-metadata">

### Author: ![TomD](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@TomD](https://discourse.processing.org/u/TomD)
#### Post date: [July 17, 2021, 2:04pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/3 "2021-07-17T14:04:45Z")

</div>

Also, to increment your loop index you can type ++ or – to decrement by 1.  
eg:

```auto
for (int i=0; i<someNumber; i++){
}

for (int i=10; i>someNumber; i--){
}

```

---

<div class="post-metadata">

### Author: ![mojinovi](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mojinovi](https://discourse.processing.org/u/mojinovi)
#### Post date: [July 17, 2021, 2:27pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/4 "2021-07-17T14:27:50Z")

</div>

Thanks TomD for looking at my issue,  
I figured it out! 🙂  
If you go in the examples folder\>Demos\>Performance, you’ll find a “LineRendering” example,  
They use P2D renderer when defining the scree size,  
It solves the issue 🙂 and give a lil explanation,

Thanks again for checking!

Oh and to answer your advices:  
-I need ~2K lines for my project (I didn’t post the actual project, just a sample code to illustrate)  
-My project involves re computation at each steps,  
-Thanks for all the hints

---

<div class="post-metadata">

### Author: ![TomD](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@TomD](https://discourse.processing.org/u/TomD)
#### Post date: [July 17, 2021, 2:33pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/5 "2021-07-17T14:33:42Z")

</div>

You’re welcome!

Glad you got it figured out, tbh I hadn’t realised that the hardware accelerated renderer could improve performance so significantly, good to know.

The benefits of having a working GPU I guess! haha

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 17, 2021, 2:52pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/6 "2021-07-17T14:52:45Z")

</div>

Hello,

There are references to _renderers_ here:

- [https://processing.org/reference/environment/#Renderers](https://processing.org/reference/environment/#Renderers)
- [Render Techniques / Processing.org](https://processing.org/tutorials/rendering/)
- [P3D / Processing.org](https://www.processing.org/tutorials/p3d/)

A related topic:

> [@Running really slow for a relatively simple program](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/2):
>
> Hello, It rocks with: size(1000, 1000, FX2D); and size(1000, 1000, P3D); P3D rapidly declined as density increased. I added this to monitor frameRate: if (frameCount%5 == 0) surface.setTitle(str(frameRate)); [https://processing.org/reference/setTitle\_.html](https://processing.org/reference/setTitle_.html) There is a comment about FX2D here: [https://processing.org/reference/environment/](https://processing.org/reference/environment/)slight_smile

`:)`

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [July 17, 2021, 7:42pm UTC](https://discourse.processing.org/t/this-simple-sketch-runs-much-faster-on-p5-js-60fps-than-processing-java-5fps/31300/7 "2021-07-17T19:42:12Z")

</div>

Try out: `size(800, 800, FX2D);`  
[Processing.org/reference/size\_.html](http://Processing.org/reference/size_.html)
