View Full Version : Making scripts as efficient as can be
Bonfield
10-04-2011, 08:50 AM
hi, i was wondering what the best way to keep scripts as efficient and tips on memory management etc, is it just as simple to limit calls dtms, arrays anything really complex? or does good logic incorporate all this?
i havent got any problems at the moment, any tips would be greatly appreciated
sorry if this thread is sorta spamish or in the wrong place
im sort of aiming for a discussion about efficiency, i know simple things along this lines of this
h := High(Array);
for i:=0 to h do
is better than
for i:=0 to High(Array) do
im hoping for a discussion about this, and it will help me better my understanding
Wizzup?
10-04-2011, 09:50 AM
I really wouldn't care about that if I were you, at least not if it is a function that isn't written just to perform fast. (like TPA functions in Simba and even those are ancient)
KingKong
10-04-2011, 09:56 AM
Well if you want your scripts to be as efficient as possible, the first thing i would suggest is making your own functions to do everything. The SRL and Reflection library is not the most efficient(yes its not, so don't bother saying it is) in terms of mem usage since its written for a wide audience and has to be easily understood. If you want your script to be efficient then you have to do most of the work. Things like gathering IDs, colors must be done beforehand rather than doing it on the fly. In general though, i do this in all my scripts:
Use loops sparingly
Use 'static' pixels
dont call timerunning/other similar stuff too much
color functions are not as efficient as you might think(tpa/atpa etc..)
and make ur own reflection functions since the ones in ref library give too much information without asking for it.
Bonfield
10-04-2011, 11:10 AM
I really wouldn't care about that if I were you, at least not if it is a function that isn't written just to perform fast. (like TPA functions in Simba and even those are ancient)
I understand that, but it was the only thing I could think of quickly, the example I provdied wasn't the best.
Iam more thinking of tips on managing memory, finding leaks and making efficient code for pascalscript hopfully RUTIS and general coding
Well if you want your scripts to be as efficient as possible, the first thing i would suggest is making your own functions to do everything. The SRL and Reflection library is not the most efficient(yes its not, so don't bother saying it is) in terms of mem usage since its written for a wide audience and has to be easily understood. If you want your script to be efficient then you have to do most of the work. Things like gathering IDs, colors must be done beforehand rather than doing it on the fly. In general though, i do this in all my scripts:
Use loops sparingly
Use 'static' pixels
dont call timerunning/other similar stuff too much
color functions are not as efficient as you might think(tpa/atpa etc..)
and make ur own reflection functions since the ones in ref library give too much information without asking for it.
Thanks for that, any reason you don't want to suggest additions to SRL that are more efficient than the current ones? So calling a heap of loops creates a bottleneck? (don't really know if that the right word to use here) basically increases CPU usage?
I can see the reason for static collude, I'm a fan of using blacklists, as I see them as a fast way of item finding
What's wrong with the current colour finding functions? I have never witnessed or heard of anything?
Reflection is a whole new thing never had much to do but create a worldworder when reflection was first released, can't you wrap the function to only return the few results you need?
KingKong
10-04-2011, 12:31 PM
Thanks for that, any reason you don't want to suggest additions to SRL that are more efficient than the current ones?
they wouldnt be considered reliable. eg: i check certain pixels to see if bank screen is open or not instead of using bankscreen
So calling a heap of loops creates a bottleneck? (don't really know if that the right word to use here) basically increases CPU usage?
well not really, what i meant to say was people often loop for too long. eg: smithing one bar takes a certain amount of time in rs and i see people waiting for either too long or not enough.
I can see the reason for static collude, I'm a fan of using blacklists, as I see them as a fast way of item finding
What's wrong with the current colour finding functions? I have never witnessed or heard of anything?
nothing wrong with them, people just dont know how and when to use them and often think its more efficient than ref.
Reflection is a whole new thing never had much to do but create a worldworder when reflection was first released, can't you wrap the function to only return the few results you need?
yes u can but the useless information is still gathered which is a waste of resources.
aaa
masterBB
10-04-2011, 03:53 PM
What is efficient? Fast for the computer? Or fast for you? I think it's important to find a way between both. Not to slow, so people can still run multiple bots at once. Not to 'efficient programmed' so you it's not that you can finally release a simple bot after two years of development, where a minor change can take ages.
Fastest? Most stuff can be done faster when they are pre-compiled. I say most, cause it doesn't make sense to make a plus or minus function in a pascal plugin. That would only add another function call. But that would require an extra file which could contain a virus. A bit to much in most cases, right?
If you want to stay in pascal script it's pretty easy. Try to include as few functions as possible and try to reduce the amount of function calls. Don't call srl functions like marktime if performance is important. Every thing will take some time. A function call too. So splitting the functions in multiple smaller ones is so much pretier for the eye. But is in fact a very tiny bit slower. Using 20 functions calls to acomplish something will probably be a very tiny bit faster as using 30 function calls for the same. You probably don't want to go this far?
Math, math and math. This is one of the things were you can spare some cpu power for the more important things in life. Let say you want to know if point a is closer than 20 pixels from point b. Instead of square((a.x-b.x)^2 + (a.y-b.y)^2) < 20 use (a.x-b.x)(a.x-b.x) + (a.y-b.y)(a.y-b.y) < 20*20. One less heavy function call 'square', and multiplieing instaed of squaring can be faster too.
Memory? It's a joke in pascal script. Most things don't take up much memory. The only ones that do are objects where you get an integer instead of the object itself when you trace it. So use freeX when possible.
What is efficient? Fast for the computer? Or fast for you? I think it's important to find a way between both. Not to slow, so people can still run multiple bots at once. Not to 'efficient programmed' so you it's not that you can finally release a simple bot after two years of development, where a minor change can take ages.
Fastest? Most stuff can be done faster when they are pre-compiled. I say most, cause it doesn't make sense to make a plus or minus function in a pascal plugin. That would only add another function call. But that would require an extra file which could contain a virus. A bit to much in most cases, right?
If you want to stay in pascal script it's pretty easy. Try to include as few functions as possible and try to reduce the amount of function calls. Don't call srl functions like marktime if performance is important. Every thing will take some time. A function call too. So splitting the functions in multiple smaller ones is so much pretier for the eye. But is in fact a very tiny bit slower. Using 20 functions calls to acomplish something will probably be a very tiny bit faster as using 30 function calls for the same. You probably don't want to go this far?
Math, math and math. This is one of the things were you can spare some cpu power for the more important things in life. Let say you want to know if point a is closer than 20 pixels from point b. Instead of square((a.x-b.x)^2 + (a.y-b.y)^2) < 20 use (a.x-b.x)(a.x-b.x) + (a.y-b.y)(a.y-b.y) < 20*20. One less heavy function call 'square', and multiplieing instaed of squaring can be faster too.
Memory? It's a joke in pascal script. Most things don't take up much memory. The only ones that do are objects where you get an integer instead of the object itself when you trace it. So use freeX when possible.
This was a very good read, thanks. Rep +
~Home
If you are going to save CPU then make the script in complete reflection(no color functions at all) then run it and slide the FPS bar to its lowest. Cuts my CPU from 60% to 10%
Wanted
10-04-2011, 09:44 PM
The efficiency is very important in the long run, but going overboard with it is a huge waste.
This is very trivial when compared to the real efficiency you should be aiming for, and that is the way the script runs.
By that I mean your wait times and wait loops, not calling things too soon or late, calling something more times than 1 if not needed, not causing lag or resources usage, basically what I am saying is the end result script run feeling more professional.
Things like arbitrary waits (not looping waits i.e. WaitFunc), not randomizing enough, and other bot like stuff.
The coding and memory efficiency is important but not nearly as important as the runtime efficiency.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.