MildlyShoey Posted May 8, 2019 Share Posted May 8, 2019 These results are taken from a plugin I wrote today: https://www.nexusmods.com/newvegas/mods/66931You can view the exact results here: https://drive.google.com/drive/folders/1ElqfIY4X95lZ3tUOyPOTI82Xo_BMiVWb I plan on updating this post as I test more scripts, but I'll cover the important stuff from what I've already tested: Set vs Let: 1. "set" is notably faster than "let". When using simple values or math (i.e. setting iTemp to 1 or 1*30/5), set is anywhere from 2-10x faster than let.2. When using "GetName WeapNV9mmPistol", "set" is consistently one hundred and fifty times faster than "let". This is likely a quirk of how strings are handled by "let", as a similar discrepancy occurs when "sv_construct" is combined with let. If using "ToString"/$ or entering it as raw text (i.e. let String := "Test"), it performs correctly.3. 5000 loops using "set iLoopTest to iLoopTest + 1" takes approximately 12ms to execute, with "let iLoopTest += 1" taking 22ms.4. Despite these, it takes approximately 0.0020625ms to execute "let iTemp := 1" and 0.0001875ms to execute "set iTemp to 1". You should not be afraid of using "let", though you should avoid it when possible. "set" should be used unless you are in doubt, performing math that has a chance of silently failing (i.e. dividing by 0), assembling a complex or long string (strings with a length of over 50 generally can't be assembled or executed properly without "let"), or interacting with arrays, but it is not something significant (unless you are combining string variables with it). "while" loops "while" loops don't impact performance in a notable manor themselves. Executing "let sTemp := GetName WeapNV9mmPistol" 200 times with a "while" loop or by entering it 200 times takes approximately 20ms on my rig either way. This isn't really surprising, but I feel it's of note anyways as I personally use "while" loops to execute a significant amount of code somewhat often. Functions vs Integration "call" with a user defined function appears to take twice as long to execute compared to integrated code. This does appear to scale with the complexity of code, as a script that calculates the DPS of a fully modded weapon can take 300ms to execute 10000 times when integrated into a script but takes 600ms to execute the same amount of times when executed via function, with simple code being capable of under 100ms either way. SetFuctionValue appears to not affect the amount of time it takes substantially, as using "set to call UDF" with SetFunctionValue vs "call UDF" with the UDF setting a quest variable under the former circumstances (10000 executions of modded weapon DPS calc) would take approx 600ms to execute either way."Let" continues to heavily impact execution time, with "let := call UDF" taking 2-3x as long as "set to call UDF". set xVariable to call function, let sTemp := xVariable vs let sTemp := (call function) Due to the already mentioned penalty to execution speed when a UDF is combined with let, "set sString to call function, let sTemp := sString+[text]" notably outperforms a similar execution with "let", with 5000 executions taking approximately 900ms for the former and 1400ms for the latter. Something similar but much more exaggerated also happens when constructing a string using multiple weapon DPS calculation UDF calls, with the fastest execution being "set iDPS to call function 0, set iDPSR to call function 1, set sTemp to sv_construct '%.4f, %.4f,' iDPS iDPSR" taking ~220ms to perform 5000 executions, and the slowest being "let sTemp to $call function 0+', '+$call function 1" taking 1400ms to perform 5000 executions. I'm not expecting terribly much out of this thread, but if others want to share optimization tips/experiences they would be most welcome. Link to comment Share on other sites More sharing options...
Recommended Posts