Michel wrote: I implemented it in Komodo and the actual routine that controls this is something like 5 lines of code - it's trivial.
How do you control the NPS? By inserting sleeps? Or do you just sleep
at the end of the allotted time?
You can do either:
1. Sleep every N nodes where N is monitored and dynamically adjusted
2. You can sleep for S units of time where S is monitored and dynamic.
3. You can do a combination of both.
I tried using usleep and even with usleep(0) Komodo does about 17,000 nodes per second so to go faster you must either use a much higher resolution sleep function or just sleep every N nodes. And to hit your target you must constantly monitor your nodes per second and make adjustments.
To accommodate a ridiculously low number of nodes per second (such as 50) and also be able to run almost full speed you have to do a combination of both.
It's very easy to get close and estimate what you need when the option is set and then to make very small dynamic adjustments.
If you usleep 10,000 between nodes:
usleep(10000);
You will get 100 nodes per second on any unix machine. If you want to go faster than 17,000 nodes per second usleep on every node won't cut it, you would have to skip nodes, for example usleep every 10 or every 100 nodes.
You have finer control with the usleep delay but only if the usleep value is not too low - it's notoriously inaccurate in the low order bits due to all sorts of O/S overheads and is only guaranteed to delay AT LEAST the value you set. It's a very expensive call. usleep(1) is hardly any different than usleep(2) for example or even usleep(0).
So the idea is that when the option is set, you should ESTIMATE a skip factor and a sleep factor - and try to keep the skip factor as low as possible while still having a large enough sleep value for fine tuning (probably at least a 100 or more) and as the search progresses monitor the nodes per second and make fine adjustments in the sleep delay as you go to maintain the target NPS.
It probably sounds a lot more complicated than it is, but it's actually pretty simple and less than about 10 lines of code.
By the way, if your target is close to the maximum nodes per second your program is capable of, you will need a very large skip factor and a very low sleep delay and it will more difficult nailing down the target NPS - but you probably shouldn't be using this for targets more than half the speed of what the program is capable of.
On windows I have not tested this - I know that in the past windows has had issues with high resolution timers and sleeps so it will take some experimentation. You can build your own super high resolution (high CPU utilization) timer by making a complex calculation N times but it won't be hardware independent so the delay amount will vary on each platform and complicate this calculation.
Capital punishment would be more effective as a preventive measure if it were administered prior to the crime.