Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Variables
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| MUSHuser
(12 posts) Bio
|
| Date
| Fri 07 Jan 2011 08:10 AM (UTC) |
| 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. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Fri 07 Jan 2011 08:29 AM (UTC) 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 | | Top |
|
| Posted by
| MUSHuser
(12 posts) Bio
|
| Date
| Reply #2 on Fri 07 Jan 2011 04:07 PM (UTC) |
| 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? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Fri 07 Jan 2011 08:15 PM (UTC) |
| 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 | | 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.
14,973 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top