Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bf9d48

Browse files
author
ahotko
committed
Added Timing Sample, minor refactoring
1 parent 163a64a commit 2bf9d48

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

‎CSharp Code Samples/CodeSamples/CodeSamples.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
<Compile Include="SyntacticSugars\PropertiesSample.cs" />
9393
<Compile Include="SyntacticSugars\StringInterpolationSample.cs" />
9494
<Compile Include="SyntacticSugars\UsingSample.cs" />
95+
<Compile Include="Timing\TimingSample.cs" />
96+
<Compile Include="Timing\TimingStopwatch.cs" />
9597
<Compile Include="TupleDeconstruction\TupleDeconstruction.cs" />
9698
<Compile Include="UsefulClasses\Dictionaries.cs" />
9799
<Compile Include="UsefulClasses\ObjectPoolSample.cs" />

‎CSharp Code Samples/CodeSamples/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using CodeSamples.SOLID.S01_SingleResponsibilityPrinciple_SRP;
88
using CodeSamples.SOLID.S04_InversionOfControl_IoC;
99
using CodeSamples.SyntacticSugars;
10+
using CodeSamples.Timing;
1011
using CodeSamples.TupleDeconstruction;
1112
using CodeSamples.Useful;
1213
using CodeSamples.UsefulClasses;
@@ -124,6 +125,11 @@ static void Main(string[] args)
124125
solidIoC.Execute();
125126
#endregion
126127

128+
#region Timing
129+
var timingSample = new TimingSample();
130+
timingSample.Execute();
131+
#endregion
132+
127133
Console.WriteLine();
128134
Console.WriteLine("End Code Samples");
129135

‎CSharp Code Samples/CodeSamples/SOLID/S01-SingleResponsibilityPrinciple_SRP/SingleResponsibilityPrincipleSample.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public override void Execute()
1111
garage.OpenForService();
1212
garage.ServiceAVehicle();
1313
garage.CloseGarage();
14+
15+
Finish();
1416
}
1517
}
1618
}

‎CSharp Code Samples/CodeSamples/SOLID/S04-InversionOfControl_IoC/InversionOfControlSample.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public override void Execute()
1414
var weirdDuck = new Duck(new SpanishQuack(), new NormalFly());
1515
weirdDuck.Quack();
1616
weirdDuck.Fly();
17+
18+
Finish();
1719
}
1820
}
1921
}

‎CSharp Code Samples/CodeSamples/SampleExecute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void Title(string title)
3333
{
3434
PushColors();
3535
SetTitleColor();
36+
Console.WriteLine();
3637
Console.WriteLine(title);
3738
PopColors();
3839
Console.WriteLine("============================================================");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CodeSamples.Timing
2+
{
3+
public class TimingSample : SampleExecute
4+
{
5+
public override void Execute()
6+
{
7+
Title("TimingSample");
8+
Section("Stopwatch Timing");
9+
10+
var stopwatchTiming = new TimingStopwatch();
11+
stopwatchTiming.Go();
12+
13+
Finish();
14+
}
15+
}
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Threading;
4+
5+
namespace CodeSamples.Timing
6+
{
7+
public class TimingStopwatch
8+
{
9+
private void StopwatchSampleCreateManually()
10+
{
11+
var stopWatch = new Stopwatch();
12+
13+
Console.Write("Going to sleep for a while, tired b/c of manual labor...");
14+
stopWatch.Start();
15+
Thread.Sleep(2000);
16+
stopWatch.Stop();
17+
Console.WriteLine($"woke up after {stopWatch.Elapsed}, that is {stopWatch.Elapsed.TotalMilliseconds} ms.");
18+
}
19+
20+
private void StopwatchSampleCreateAuto()
21+
{
22+
23+
Console.Write("Going to sleep for a while, tired b/c of auto create...");
24+
var stopWatch = Stopwatch.StartNew();
25+
Thread.Sleep(2000);
26+
stopWatch.Stop();
27+
Console.WriteLine($"woke up after {stopWatch.Elapsed}, that is {stopWatch.Elapsed.TotalMilliseconds} ms.");
28+
}
29+
30+
public void Go()
31+
{
32+
StopwatchSampleCreateManually();
33+
StopwatchSampleCreateAuto();
34+
}
35+
}
36+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /