multithreading - Run time of Threadpool in c# .NET4.0 -


hi want measure run time of function in code. use threadpool running function.

system.diagnostics.stopwatch w = new system.diagnostics.stopwatch();         w.start();         threadpool.queueuserworkitem(new waitcallback(f));         w.stop();         label1.text = w.elapsed.tostring();  f(){ //array.sort()} 

the f() sort numbers.

example: 60000000 numbers stopwatch shows:with threadpool 00:00:00.0003201 performance whitout threading 00:00:06.8651903 ???

for 1000 numbers threadpool 00:00:00.0001801 , whitout 00:00:00.0011956 ???

now have questions?

1.could threadpool decrease run time or made mistake?

2.could stopwatch measure run time of functions run simultaneously?

1.could threadpool decrease run time or made mistake?

afraid made mistake. queueuserworkitem returns allowing current thread continue while work being done on different thread. therefore w.stop(); called after work begins. doesn't wait work item complete. measured how long takes add item queue, not how long takes complete work.

2.could stopwatch measure run time of functions run simultaneously?

you start/stop watch inside function, or have delegate function proxy actual function. delegate wrap actual function/work start/stop calls , send resulting time needs logged to.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -