c++ - How much impact (time) can a single 'if' statement have within a tight loop? -


i'm working on application in c++ uses tight loop iterate through states in our fsm. right now, because of tight loop, uses 100% cpu, , our customers don't that. wanted try putting sleep(1) in tight loop loosen up, we're worried that make sleep long between states our large customers (whose states change quickly!). thinking of trying this:

if(smallcustomer) {     sleep(1); } 

and smallcustomer defined somewhere else when program started up. 'if' statement slow things down as sleep would, , defeating own purpose?

your implication fsm shouldn't need 100% of cpu, leads me assume spending lot of time doing nothing except checking see if need move next state or not. worried sleeping "too long" larger customers, means concerned event missed: queue filling, mouse click, packet being received, completion of disk i/o, key being pressed, whatever. should refactor trigger asynchronously on event (or events) instead of hogging cpu doing nothing in loop.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -