Local variables vs. global ones
in
Programming Questions
•
3 years ago
This is a rather general programming question:
Is it preferable to create temporarily used variables locally only, or is there a speed-benefit in declaring them global (or semi-global within their routine/class etc.)
In short, what are the benefits and disadvantages of the following versions:
- void draw() {
- float f;
- for (int i=0;i<1000;i++){
- f = random(0,1);
- }
- }
Or:
- float f;
- void draw() {
- for (int i=0;i<1000;i++){
- f = random(0,1);
- }
- }
Or:
- void draw() {
- for (int i=0;i<1000;i++){
- float f;
- f = random(0,1);
- }
- }
1