Arn
Member
- Joined
- Mar 8, 2010
- Messages
- 282
- Reaction score
- 18
Hi all,
I'm working on a new OT, and I wanted to figure out which way of storing player information was faster. You can either do something like this:
setStorage(100, 1337)
or you can store the same value in a global variable:
GLOBAL_X = 1337
Now, I wrote two scripts in talkactions that count to some huge number (2 million, 10 million, etc) and then compares the time. So lets look at version 1:
You can see that for the while loop (which counts to 2 million), we get the storage once, and we set the storage once. We do this 2 million times, and then compare the time. Lets look at version two.
We do the same exact thing, but we replace getStorage with GLOBAL_X and we replace doSetStorage with GLOBAL_X = x. We do this 2 million times as well.
Now lets compare the results (on my server):
counting to 2 million with Storage = 8 seconds
counting to 2 million with Globals = 1 second
counting to 10 million with Storage = crashed my server and made my virtual machine unresponsive. I'm at work and can't log back in -.-
counting to 10 million with Globals = 1 second
edit: was able to reconnect.
counting to 100 million with Globals = 6 seconds
So my conclusion is that storing to globals is much faster than playerstorage or globalstorage. Thoughts? Comments?
Thanks,
-Arn
- - - Updated - - -
Nobody cares? Nobody has any input at all?
I'm working on a new OT, and I wanted to figure out which way of storing player information was faster. You can either do something like this:
setStorage(100, 1337)
or you can store the same value in a global variable:
GLOBAL_X = 1337
Now, I wrote two scripts in talkactions that count to some huge number (2 million, 10 million, etc) and then compares the time. So lets look at version 1:
Code:
function onSay(cid, words, param, channel)
doCreatureSay(cid, getWorldUpTime())
local x = getStorage(100)
while (getStorage(100) ~= 2000000) do
x = x + 1
doSetStorage(100, x)
end
doCreatureSay(cid, getWorldUpTime())
doCreatureSay(cid, getStorage(100))
return true
end
You can see that for the while loop (which counts to 2 million), we get the storage once, and we set the storage once. We do this 2 million times, and then compare the time. Lets look at version two.
Code:
function onSay(cid, words, param, channel)
doCreatureSay(cid, getWorldUpTime())
local x = GLOBAL_X
while (GLOBAL_X ~= 2000000) do
x = x + 1
GLOBAL_X = x
end
doCreatureSay(cid, getWorldUpTime())
doCreatureSay(cid, GLOBAL_X)
return true
end
We do the same exact thing, but we replace getStorage with GLOBAL_X and we replace doSetStorage with GLOBAL_X = x. We do this 2 million times as well.
Now lets compare the results (on my server):
counting to 2 million with Storage = 8 seconds
counting to 2 million with Globals = 1 second
counting to 10 million with Storage = crashed my server and made my virtual machine unresponsive. I'm at work and can't log back in -.-
counting to 10 million with Globals = 1 second
edit: was able to reconnect.
counting to 100 million with Globals = 6 seconds
So my conclusion is that storing to globals is much faster than playerstorage or globalstorage. Thoughts? Comments?
Thanks,
-Arn
- - - Updated - - -
Nobody cares? Nobody has any input at all?
Last edited: