I've been tinkering with my healing functions etc... and I've devised a way to have one function check against my priorities and cure accordingly. Previously I had a function for each cure type(herb, salve, smoke, etc..) that would check it's affliction priority and cure accordingly. I would then place calls to these multiple curing functions in a single function that would get called on my prompt.
What I've changed it to is one function that loops through a table to determine cure order(herb, salve, smoke, etc..) that then loops through another table to check for affliction order. Then it heals accordingly. This method effectively saves me about 200 or more lines of code in various function and table construction.
I'm typing this on my phone else I would provide code for better explanation. Basically what I want to know is which method is faster as well as tips, sites, or even code I could use to test the speed of certain scripts. As always thanks in advance for any help, tips, or advice.
Speed of scripts
Re: Speed of scripts
I've read through this a couple of times, and I honestly don't know what you're asking here. You've asked which method is faster, but I don't know what two methods you're comparing. Are you asking if it's faster to loop through tables or to hard code it?
Re: Speed of scripts
Both scenarios loop through tables. One just uses multiple functions called in a single function and the other is just one function. I know it's hard to picture without code, and my programming grammar may be off, but in about 8 hours I can give you guys some code to look at.
Re: Speed of scripts
Alright so here is some code to help explain the two different methods.
This is the new method:
This is the new method:
This is the old method:
So which method do you guys think is faster? Also, still would like to know how I could check this own my own without needing to know a bunch of coding logic etc...
Re: Speed of scripts
You can use the system speed indicator S: value on the far right of the command line. This shows the time in milliseconds that the last line needed to process (triggers + all scripts).
I might add some profiling tool though.
I might add some profiling tool though.
Re: Speed of scripts
I'd say the difference is probably negligible on a moderately sided system. I'd worry more about which is easier for you to debug later.
Re: Speed of scripts
^ That's a good point. Being a fairly new, self taught, wanna be Lua programmer I tend to forget about that aspect. As well the difference probably is negligible.
Re: Speed of scripts
my curing system doesn't hardcode anything into the curing script. It's just an engine that parses through a user-defined set of arrays that handles afflictions, balances, cures, special usage instructions, etc. I like it because the actual curing code is very small and easy to debug, and the arrays themselves are simple. Added bonus, it works without modification on any mud that I've come across.