SRL Archive - OSR Help

Is global vars faster than non global vars?


Main

2010-04-04 18:47:58

I changed some of my variables from global to procedure vars, now the time for me to complete one load is slower.

Is global vars faster than procedure/function vars? or I changed something within my script.

bullzeye95

2010-04-04 18:53:11

Local vars must be initialized every time their function or procedure is called, but changing to local vars from global vars should not in any way affect the overall speed of your script, unless you are calling those functions/procedures millions of times each load (and even if you are, it would still probably not make a big difference in speed)… It must be something else that is making your script run slower.

Awkwardsaw

2010-04-04 19:24:18

afaik, golbal vars slowdown compile time, and local vars slowdown procs/ functions, albiet not by much, if at all :)

i luffs yeww

2010-04-04 19:47:35

Awkward (I can't believe I just pressed tab after typing 'Awk'.. >_>), that would logically make sense, although I think this is a different problem. Going from local to global or global to local shouldn't change anything that's noticeable. I'm sure it's something else, Main.

Awkwardsaw

2010-04-04 19:55:43

From: Awkwardsaw
afaik, golbal vars slowdown compile time, and local vars slowdown procs/ functions, albiet not by much, if at all :)


i know, :)

Main

2010-04-04 19:57:14

This is fucked up :(


Achieved 864 log per Hour or 116724 exp per hour.
Achieved 863 log per Hour or 116621 exp per hour.
Achieved 863 log per Hour or 116511 exp per hour.
Achieved 862 log per Hour or 116408 exp per hour.
Achieved 861 log per Hour or 116305 exp per hour.
Achieved 860 log per Hour or 116196 exp per hour.
Achieved 859 log per Hour or 116096 exp per hour.
Achieved 859 log per Hour or 115994 exp per hour.
Achieved 858 log per Hour or 115888 exp per hour.
Achieved 857 log per Hour or 115786 exp per hour.
Achieved 856 log per Hour or 115686 exp per hour.
Achieved 856 log per Hour or 115584 exp per hour.
Achieved 855 log per Hour or 115482 exp per hour.
I restart scar and it continues… WTF

Sex

2010-04-04 20:27:49

Show us the script..

i luffs yeww

2010-04-04 20:45:51

Wait did it change after you restarted? If so then it was just a SCAR error.

Main

2010-04-04 20:56:37

Procedure Mainloop;
Begin
Rt:=0;
Marktime(Rt);
If Openbank then
Begin
Banking;
GTH;
lt:=0;
repeat
Light;
Disguise('Lighting log #'+inttostr(lt)+'.');
until (lt=28)
GTB;
Walktobank;
Writeln('Achieved '+Inttostr(86400000000/rt)+' log per Hour or '+Inttostr(11664000000000/rt)+' exp per hour.');
End;
End;

I think the marktime is whats causing it

i luffs yeww

2010-04-04 21:06:38

Well that's not the whole script. The MarkTime alone wouldn't do anything because it takes no time at all.

Infantry001

2010-04-04 21:31:13

It's gotta be something with your logic, although I can't find anything in that snippet you gave us.

Does it change during the script run? Or after every time you start it up again?

Wanted

2010-04-04 22:01:35

Global vars should be avoided much as possible.

Infantry001

2010-04-04 22:07:33

From: IceFire908
Global vars should be avoided much as possible.


I never really understood why though :/

i luffs yeww

2010-04-04 22:12:34

For debugging purposes. If there's a problem with something you have to look through the whole script do check variables effectively (if they're global). However, if it's local, they don't interact with each other, and they stay in place, which makes it much simpler to debug. :)

Main

2010-04-04 23:37:42

I guess.. so you have a lot of boolean functions?

i luffs yeww

2010-04-04 23:50:00

What?

trecool999

2010-04-09 13:24:18

From: IceFire908
Global vars should be avoided much as possible.

Why's that? In any other language the opposite would be recommended…

Nava2

2010-04-09 15:59:51

From: trecool999
Why's that? In any other language the opposite would be recommended…


What languages.. o.O Last I checked, in most languages its frowned upon.

"They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, (unless they reside in protected memory) and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity. See Action at a distance. However, in a few cases, global variables can be suitable for use. For example, they can be used to avoid having to pass frequently-used variables continuously throughout several functions."
http://en.wikipedia.org/wiki/Global_variable

In theory, locals are slower based on initiation time. But, in general you should try to pass around parameters through functions and out/var parameters. Its much easier to find where you errors are if you can isolate the location of change.

i luffs yeww

2010-04-09 22:48:55

From: trecool999
Why's that? In any other language the opposite would be recommended…


From: Nava2
What languages.. o.O Last I checked, in most languages its frowned upon.

"They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, (unless they reside in protected memory) and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity. See Action at a distance. However, in a few cases, global variables can be suitable for use. For example, they can be used to avoid having to pass frequently-used variables continuously throughout several functions."
http://en.wikipedia.org/wiki/Global_variable

In theory, locals are slower based on initiation time. But, in general you should try to pass around parameters through functions and out/var parameters. Its much easier to find where you errors are if you can isolate the location of change.


From: i luffs yeww
For debugging purposes. If there's a problem with something you have to look through the whole script do check variables effectively (if they're global). However, if it's local, they don't interact with each other, and they stay in place, which makes it much simpler to debug. :)


wat