# Editing PShape vertices vs drawing immediate mode

**URL:** <https://discourse.processing.org/t/editing-pshape-vertices-vs-drawing-immediate-mode/31626>\
**Category:** Processing\
**Created:** [August 8, 2021, 3:59pm UTC](https://discourse.processing.org/t/editing-pshape-vertices-vs-drawing-immediate-mode/31626 "2021-08-08T15:59:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [August 8, 2021, 3:59pm UTC](https://discourse.processing.org/t/editing-pshape-vertices-vs-drawing-immediate-mode/31626/1 "2021-08-08T15:59:31Z")

</div>

I knew that PShape is generally faster than immediate mode (begin/endShape), but I didn’t know if editing PShape vertices before drawing ends up slower or faster than the immediate mode. So I tested it with the following codes. I run it a few times and every time the difference was very small - so it seems it doesn’t matter which mode to use when you need to edit the entire vertices.

PShape 136.97ms  
immediate mode 142.69ms  
(on Windows 10 / Surface Pro 6 i5 / Processing 3.5.4)

PShape:

```auto
PShape s;
int frames = 0;
int totalElapsed = 0;
int totalFrames = 100;
int N = 100000;

void setup() {
  size(800, 800);
  
  s = createShape();
  s.beginShape();
  for(int i = 0; i < N; i++) {
    float theta = (float)frames * i / N * 2 * PI;
    s.vertex(100 * cos(theta), 100 * sin(theta));
  }
  s.endShape(CLOSE);
}

void draw() {
  background(255);
  int t = millis();

  for(int i = 0; i < N; i++) {
    float theta = (float)frames * i / N * 2 * PI;
    s.setVertex(i, 100 * cos(theta), 100 * sin(theta));
  }
  shape(s, 0, 0);
  
  t = millis() - t;
  
  frames++;
  if (frames < totalFrames) {
    totalElapsed += t;
  }
  else if (frames == totalFrames) {
    println("average time: " + (float)totalElapsed / (float)totalFrames + " ms");
  }
}

```

immediate mode:

```auto
PShape s;
int frames = 0;
int totalElapsed = 0;
int totalFrames = 100;
int N = 100000;

void setup() {
  size(800, 800);
}

void draw() {
  background(255);
  int t = millis();

  beginShape();
  for(int i = 0; i < N; i++) {
    float theta = (float)frames * i / N * 2 * PI;
    vertex(100 * cos(theta), 100 * sin(theta));
  }
  endShape(CLOSE);
  
  t = millis() - t;
  
  frames++;
  if (frames < totalFrames) {
    totalElapsed += t;
  }
  else if (frames == totalFrames) {
    println("average time: " + (float)totalElapsed / (float)totalFrames + " ms");
  }
}

```
