vb.net - Why will thread run faster with thread.Join in Visual Basic .Net -


i have 2 windows form test performance of using threat

i looping of 500

for integer = 1 500     'form 1 scenario     dim thread1 new system.threading.thread(addressof insertrecord1)     thread1.start(runningid)     dim thread2 new system.threading.thread(addressof insertrecord1)     thread2.start(runningid)     dim thread3 new system.threading.thread(addressof insertrecord1)     thread3.start(runningid)     dim thread4 new system.threading.thread(addressof insertrecord1)     thread4.start(runningid) next 

form 2 scenario

for integer = 1 500     'form 2 scenario     dim thread1 new system.threading.thread(addressof insertrecord1)     thread1.start(runningid)     dim thread2 new system.threading.thread(addressof insertrecord1)     thread2.start(runningid)     dim thread3 new system.threading.thread(addressof insertrecord1)     thread3.start(runningid)     dim thread4 new system.threading.thread(addressof insertrecord1)     thread4.start(runningid)     thread1.join()     thread2.join()     thread3.join()     thread4.join() next 

apparently scenario 2 faster scenario 1. why??

this data collected

scenario 1 take (milliseconds): 2578   3188   3078   2984   3250 scenario 2 take (milliseconds): 1890   1969   1828   1938   1860 

i think shows inserts not scale well. first scanario launches 2000 threads , waits them finish - second scenario launches 4 threads , waits them finish, 500 times.

using threads adds overhead execution can slow down code, if threads end same database cannot handle many connections execution times worse. maybe test example without multiple threads, put calls directly loop , @ numbers, possibly runs faster.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -