Results 1 to 19 of 19

Thread: Is global vars faster than non global vars?

  1. #1
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default Is global vars faster than non global vars?

    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.
    Oh Hai Dar

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    afaik, golbal vars slowdown compile time, and local vars slowdown procs/ functions, albiet not by much, if at all
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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.

  5. #5
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    afaik, golbal vars slowdown compile time, and local vars slowdown procs/ functions, albiet not by much, if at all
    i know,
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  6. #6
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    This is fucked up
    SCAR Code:
    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
    Oh Hai Dar

  7. #7
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Show us the script..
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  8. #8
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  9. #9
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    SCAR Code:
    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
    Oh Hai Dar

  10. #10
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  11. #11
    Join Date
    Jun 2006
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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?

  12. #12
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Global vars should be avoided much as possible.

  13. #13
    Join Date
    Jun 2006
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by IceFire908 View Post
    Global vars should be avoided much as possible.
    I never really understood why though :/

  14. #14
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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.

  15. #15
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

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

  16. #16
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    What?

  17. #17
    Join Date
    Feb 2008
    Location
    S
    Posts
    57
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by IceFire908 View Post
    Global vars should be avoided much as possible.
    Why's that? In any other language the opposite would be recommended...

  18. #18
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by trecool999 View Post
    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.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  19. #19
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Quote Originally Posted by trecool999 View Post
    Why's that? In any other language the opposite would be recommended...
    Quote Originally Posted by Nava2 View Post
    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.
    Quote Originally Posted by i luffs yeww View Post
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •