Cheat Engine
The Official Site of Cheat Engine

Author Message
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 158
Location: Russia

Posted: Sun Jun 18, 2017 2:26 am    Post subject: Comparing the execution time of two functions

 Code: function NoOptimizeCode()    --[[Presumably not optimized code]]-- end function OptimizeCode()    --[[Presumably optimized code]]-- end local countRepeat = 100000 -- add more cycle local x1 = 0 local x2 = 0 x1 = os.clock() for i = 1, countRepeat do NoOptimizeCode() end x2 = os.clock() for i = 1, countRepeat do OptimizeCode() end local deltaTimeOptimize = (os.clock() - x2) local deltaTimeNoOptimize = (x2 - x1) print(string.format("%.2f\n",  deltaTimeNoOptimize/deltaTimeOptimize))

Examples:

 Code: function NoOptimizeCode()    if string.match('mov eax, [edx]', 'edx') then    end end function OptimizeCode()    if string.find('mov eax, [edx]', 'edx') then    end end --> 1.38

 Code: local tableA = {'A', 'B', 'C'} function NoOptimizeCode()    local t = #tableA    for i = 1, t do    end end function OptimizeCode()    for i = 1, #tableA do    end end --> 1.04

 Code: tableA = {'A', 'B', 'C'} local tableB = {'A', 'B', 'C'} function NoOptimizeCode()    for i = 1, #tableA do    end end function OptimizeCode()    for i = 1, #tableB do    end end --> 1.14

 Code: function NoOptimizeCode()  tableA = {'A', 'B', 'C'} end function OptimizeCode()  local tableB = {'A', 'B', 'C'} end --> 1.08

Try to compatible for:
string.match (s, pattern [, init])
string.gmatch (s, pattern)
string.gsub (s, pattern, repl [, n])
string.find (s, pattern [, init [, plain]])

And other things that you wanted to know for comparison
atom0s
Moderator
Reputation: 157

Joined: 25 Jan 2006
Posts: 8104
Location: 127.0.0.1

Posted: Sun Jun 18, 2017 2:47 am    Post subject:

If you have access to LuaSocket you can use its 'gettime' function for a more precise time than os.clock gives.

 Code: socket.gettime()

_________________
- Retired.
Dark Byte
Reputation: 384

Joined: 09 May 2003
Posts: 23114
Location: The netherlands

 Posted: Wed Jun 21, 2017 12:26 pm    Post subject: getTickCount() can be used as well _________________Do not ask me about online cheats. I don't know any and wont help finding them. Like my help? Join me on Patreon so i can keep helping
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 Hours Page 1 of 1

 Jump to: Select a forum Cheat Engine----------------Cheat EngineCheat Engine MacOSCheat Engine Lua ScriptingCheat Engine ExtensionsCheat Engine TutorialsGeneral GamehackingAuto Assembler tutorialsPointer tutorialsGame specific tutorialsWebbrowser stuff related tutorialsConsole ModdingLUA Tutorials General Discussions----------------General DiscussionsArtComputer TalkRandom spamArt RequestsArt TutorialsWillekeurige RotzooiGuestsHorse Excrement Cheat Requests----------------Single player cheat request Cheat Engine Downloads----------------TablesTrainersAuto Assemble scripts Coding----------------Cheat Engine SourceCETC Server and ClientsDBVMPlugin developmentGeneral programmingBinariesCrackmesGeneral programming+Game Development2D Graphics3D ModelingGameplay designWeb Development Games----------------Flash GamesGaia OnlineStick Arena Hello Kitty Forums----------------Temp
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum