[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Variables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Variables

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by MUSHuser   (6 posts)  [Biography] bio
Date Fri 07 Jan 2011 08:10 AM (UTC)  quote  ]
Message
This might be a silly question. I am just wondering about the speed of storing and retrieving a variable via two options.

1. Through the script. For example: Send("Text " + Variable)
2. Through the client. For example: Text @Variable

My guess is that it is faster to store using the script but faster to retrieve from the client. Thanks in advance for any replies.
[Go to top] top

Posted by Nick Gammon   Australia  (19,469 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 07 Jan 2011 08:29 AM (UTC)  quote  ]

Amended on Fri 07 Jan 2011 08:30 AM (UTC) by Nick Gammon

Message
It's negligible either way. Consider this:


start = utils.timer ()

local x

for i = 1, 1000000 do
  x = GetVariable ("target")
end -- for

print ("time taken =", utils.timer () - start)  


Result was:


time taken = 1.0009219048079


In other words, it got one million variables in a second.

In a normal MUD situation, you might get or set 10 or 20 variables? So, the time taken is insignificant.

And look at this:


start = utils.timer ()

for i = 1, 1000000 do
  SetVariable ("foo", "bar")
end -- for

print ("time taken =", utils.timer () - start)  


Result was:


time taken = 0.80276772542857


So it set a million variables in 8/10 of a second.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by MUSHuser   (6 posts)  [Biography] bio
Date Reply #2 on Fri 07 Jan 2011 04:07 PM (UTC)  quote  ]
Message
The GetVariable and SetVariable functions would be through the client... is that the same as using @Variable to get a variable? How does this compare with getting and setting the variables through the script?
[Go to top] top

Posted by Nick Gammon   Australia  (19,469 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 07 Jan 2011 08:15 PM (UTC)  quote  ]
Message
Well, both are done "through the client" - one uses the scripting engine, one is done by text substitution in the "send" box.

I suppose that @variable might be slightly faster if you weren't doing scripting for any other purpose. If you are already sending to script then it is using the script engine anyway. Also, if you check "expand variables" that is an extra step the client has to do (to look for @variable) which it doesn't otherwise do.

As I said, the difference would be negligible. You may as well worry whether long or short variable names would be faster. I would use whatever is easiest under the circumstances, and which is easiest to read and maintain.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,197 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]