C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
const int measurements = 10;
const int iterations = 100000000;
Stopwatch sa = new Stopwatch();
Stopwatch sna = new Stopwatch();
for (int l = 0; l < measurements; l++)
{
//With accolades
sa.Reset();
sa.Start();
for (int i = 0; i < iterations; i++)
{
Math.Sin(Math.Cos(i));
}
sa.Stop();
//Without accolades
sna.Reset();
sna.Start();
for (int i = 0; i < iterations; i++)
Math.Sin(Math.Cos(i));
sna.Stop();
Trace.WriteLine(
string.Format("With accolades: {0}, without: {1}. Winner: {2} (Difference: {3})",
sa.ElapsedTicks,
sna.ElapsedTicks,
sa.ElapsedTicks > sna.ElapsedTicks ? "Without" : "With",
Math.Abs(sa.ElapsedTicks - sna.ElapsedTicks))
);
}
}
}
} |
Output (Release mode):
With accolades: 700906185, without: 700149690. Winner: Without (Difference: 756495)
With accolades: 700437132, without: 703174752. Winner: With (Difference: -2737620)
With accolades: 700127136, without: 700321617. Winner: With (Difference: -194481)
With accolades: 701027973, without: 700240257. Winner: Without (Difference: 787716)
With accolades: 700198497, without: 702466893. Winner: With (Difference: -2268396)
With accolades: 701066196, without: 700391556. Winner: Without (Difference: 674640)
With accolades: 700194897, without: 701030781. Winner: With (Difference: -835884)
With accolades: 700373961, without: 700319403. Winner: Without (Difference: 54558)
With accolades: 701689743, without: 701044803. Winner: Without (Difference: 644940)
With accolades: 700753014, without: 700402473. Winner: Without (Difference: 350541)
Output (Debug mode):
With accolades: 835360947, without: 811710432. Winner: Without (Difference: 23650515)
With accolades: 837613278, without: 810627120. Winner: Without (Difference: 26986158)
With accolades: 838503945, without: 813787245. Winner: Without (Difference: 24716700)
With accolades: 837426222, without: 815839443. Winner: Without (Difference: 21586779)
With accolades: 834574581, without: 810887022. Winner: Without (Difference: 23687559)
With accolades: 834683697, without: 809994681. Winner: Without (Difference: 24689016)
With accolades: 836210412, without: 812255859. Winner: Without (Difference: 23954553)
With accolades: 834788529, without: 810610353. Winner: Without (Difference: 24178176)
With accolades: 839362311, without: 814297347. Winner: Without (Difference: 25064964)
With accolades: 834458130, without: 813483153. Winner: Without (Difference: 20974977)
So far lijkt
de verklaring van MS dus te kloppen... Ik ben toch wel benieuwd naar de exacte code van Phyxion...
[
Voor 28% gewijzigd door
RobIII op 30-05-2009 20:47
. Reden: Inderdaad even Stopwatch gebruikt. ]
There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.
Je eigen tweaker.me redirect
Over mij