multithreading - How can I simulate the simultaneous execution of multiple tasks in .Net? -
i run several tasks simultaneously. clear, desire simultaneous, not merely parallel -- @ point in time, want every task have consumed equal number of cpu cycles, within tolerance. how best done in .net?
there 2 ways measure this, wall clock time , cpu time. people tell use stopwatch measure performance, may or may not number want.
if care how long took execute in real time, use stopwatch, if want know how long thread running, can done native api call getthreadtimes. here article on codeproject uses it. note won't able use tpl this, need use real threads tpl recycles threads times not real execution times task.
a second option use querythreadcycletime. not give time, give number of cycles current thread has been executing, can 1 @ start , 1 @ end , subtract 2 numbers. note again task
reuses threads number may or may-not reliable unless use full threads.
be aware can't directly convert cycles->seconds
due fact many processors (especially mobile processors) not run @ fixed speed there no constant number multiply elapsed time in seconds. if using processor not vary speed simple math problem wall clock time cycles.
Comments
Post a Comment