I already gave you one. But the reason why the single threaded is a lot slower:
1 Thread:
msg = 1 ms
sleep = 50 ms
msg = 1 ms
sleep = 50 ms
msg = 1 ms
sleep = 50 ms
msg = 1 ms
sleep = 50 ms
2 threads:
msg-msg = 2 ms
sleep-sleep = 50ms
msg-msg = 2 ms
sleep-sleep = 50ms
As you can see, multi thread sleeps at the same time, single thread needs to do all the sleeps after each other. This meens that the sleep is the cause of the difference.
__
Test under heavy load (Phenom II x4):
If you redo the test without sleep (tickcount):
Code:
Output 0
Output 1
Output 2
Output 3
Output 4
Output 5
Output 6
Output 7
Output 8
Output 9
Output 10
Output 11
Output 12
Output 13
Output 14
Output 15
Output 16
Output 17
Output 18
Output 19
Output 20
Output 21
Output 22
Output 23
Output 24
Output 25
Output 26
Output 27
Output 28
Output 29
Output 30
Output 31
Output 32
Output 33
Output 34
Output 35
Output 36
Output 37
Output 38
Output 39
Output 40
Output 41
Output 42
Output 43
Output 44
Output 45
Output 46
Output 47
Output 48
Output 49
Time normal : 31
Code:
Output 38
Output 13
Output 0
Output 26
Output 39
Output 44
Output 14
Output 1
Output 27
Output 45
Output 40
Output 15
Output 2
Output 28
Output 41
Output 46
Output 16
Output 3
Output 29
Output 42
Output 47
Output 17
Output 30
Output 4
Output 43
Output 48
Output 18
Output 31
Output 5
Output 49
Output 19
Output 32
Output 6
Output 20
Output 33
Output 7
Output 10
Output 21
Output 11
Output 8
Output 34
Output 22
Output 9
Output 35
Output 12
Output 23
Output 37
Output 36
Output 25
Output 24
Time multi : 125
As I said, the sleep was the problem, this is with a good time function:
Code:
Output 0
Output 1
Output 2
Output 3
Output 4
Output 5
Output 6
Output 7
Output 8
Output 9
Output 10
Output 11
Output 12
Output 13
Output 14
Output 15
Output 16
Output 17
Output 18
Output 19
Output 20
Output 21
Output 22
Output 23
Output 24
Output 25
Output 26
Output 27
Output 28
Output 29
Output 30
Output 31
Output 32
Output 33
Output 34
Output 35
Output 36
Output 37
Output 38
Output 39
Output 40
Output 41
Output 42
Output 43
Output 44
Output 45
Output 46
Output 47
Output 48
Output 49
Normal: 0.0128041
Code:
Output 38
Output 13
Output 0
Output 26
Output 39
Output 44
Output 14
Output 1
Output 27
Output 40
Output 45
Output 15
Output 2
Output 28
Output 46
Output 41
Output 16
Output 3
Output 29
Output 42
Output 47
Output 4
Output 17
Output 30
Output 43
Output 48
Output 18
Output 5
Output 31
Output 49
Output 19
Output 6
Output 32
Output 20
Output 7
Output 10
Output 33
Output 11
Output 8
Output 21
Output 34
Output 22
Output 9
Output 12
Output 35
Output 23
Output 37
Output 36
Output 24
Output 25
Multi: 0.122748
Also useless... 50 runs is not much..
Lets do 5k runs, and use cls to clean the screen so we can see the output.
Code:
Normal: 0.401239
Multi: 10.9652
This is better..
Lets do 50k runs:
Code:
Normal: 3.16472
Multi: 109.457
50k, make 2 threads max with multi threading:
Code:
Normal: 3.2298
Multi: 3.12841
A littel bit better
Now with 4:
Code:
Normal: 3.20476
Multi: 3.41695
Hmm, that sucks...
___
Without a heavy game that takes multiple threads:
50k
Code:
Normal: 3.8366
Multi: 3.384
5k
Code:
Normal: 0.427616
Multi: 0.335064
I guess you know enought now :P.