Drakath Posted December 7, 2014 Share Posted December 7, 2014 What is more efficient: This: function showMoney(source) local playermoney = getPlayerMoney ( source ) outputChatBox(playermoney) end or this: function showMoney(source) outputChatBox(getPlayerMoney ( source )) end Is it worth storing something in local if you are gonna use it only once? Link to comment
Castillo Posted December 7, 2014 Share Posted December 7, 2014 I don't know if it's "worth", but there's no point if you are just going to use it once. Link to comment
Jaydan Posted December 7, 2014 Share Posted December 7, 2014 Well, it would make your script more readable but every time you create a variable it stores it in the memory so technically speaking I guess it would be more efficient if you didn't assign a variable to it. Either way the performance isn't going to increase/decrease greatly so do whatever you prefer Link to comment
Moderators IIYAMA Posted December 8, 2014 Moderators Share Posted December 8, 2014 Well if you wanted to know that: local player = getRandomPlayer () --test 1 -- local timeNow = getTickCount() function setMoney1() local playermoney = getPlayerMoney ( player ) setPlayerMoney(player,playermoney) end for i=1,100000 do setMoney1() -- call the function end outputChatBox(getTickCount()-timeNow .. " ms (with variable)") ------------ -- test 2 -- local timeNow = getTickCount() function setMoney2() setPlayerMoney(player,getPlayerMoney ( player )) end for i=1,100000 do setMoney2() -- call the function end outputChatBox(getTickCount()-timeNow .. " ms (without variable)") ------------ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now