|
| 11 Apr 2015 06:35 AM |
Hello guys,
I would just like to know how you would compare 2 scripts. Say you had 1 script, and decided to add a few locals in it, how would you compare the speed? Same goes for other things.
Example:
Script 1:
while true do x = 10 print(x) wait(1) end
Script 2:
while true do local x = 10 print(x) wait(1) end
How would you see if it is faster?
Also, could you tell me all the ways you know how to make a script has fast and as efficient as possible. |
|
|
| Report Abuse |
|
|
murcury57
|
  |
| Joined: 30 Jun 2010 |
| Total Posts: 90299 |
|
| |
|
|
| 11 Apr 2015 06:46 AM |
So like this?
while true do local Started = tick() local x = 10 local Ended = tick() print(x) print(Started-Ended) wait(1) end
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 Apr 2015 07:32 AM |
| You'd have to put the print before your diff |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2015 08:27 AM |
function TestSpeed(func) local start = tick() func() return tick() - start end
local n1 = TestSpeed(function() x = 10 print(x) wait(1) end)
local n2 = TestSpeed(function() local x = 10 print(x) wait(1) end)
print("Time to execute test#1: "..n1) print("Time to execute test#2: "..n2) local faster = (n1 < n2) and "test#1" or "test#2" print("Faster: "..faster) |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2015 08:29 AM |
Also, my results:
10 10 Time to execute test#1: 1.0176703929901 Time to execute test#2: 1.0070385932922 Faster: test#2 |
|
|
| Report Abuse |
|
|
| |
|
| |
|