Skip to content

Commit f8b5174

Browse files
committed
TimeStamp tests and comments.
1 parent 7334692 commit f8b5174

5 files changed

Lines changed: 69 additions & 17 deletions

File tree

src/HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="Recording\RecorderTestWithLongHistogram.cs" />
7070
<Compile Include="Recording\RecorderTestWithLShortHistogram.cs" />
7171
<Compile Include="ShortHistogramTests.cs" />
72+
<Compile Include="TimeStampTests.cs" />
7273
</ItemGroup>
7374
<ItemGroup>
7475
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Threading;
4+
using NUnit.Framework;
5+
6+
namespace HdrHistogram.UnitTests
7+
{
8+
[TestFixture]
9+
public class TimeStampTests
10+
{
11+
[Test]
12+
public void TimeStamp_values_are_accurate()
13+
{
14+
var delay = TimeSpan.FromSeconds(1);
15+
var expected = TimeStamp.Seconds(delay.Seconds);
16+
17+
var start = Stopwatch.GetTimestamp();
18+
Thread.Sleep(delay);
19+
var end = Stopwatch.GetTimestamp();
20+
var actual = end - start;
21+
22+
Assert.AreEqual(expected, actual, expected * 0.05);
23+
Assert.AreEqual(TimeStamp.Seconds(60), TimeStamp.Minutes(1));
24+
Assert.AreEqual(TimeStamp.Minutes(60), TimeStamp.Hours(1));
25+
}
26+
}
27+
}

src/HdrHistogram/HdrHistogram.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Compile Include="Properties\AssemblyInfo.g.cs" />
8484
<Compile Include="Recorder.cs" />
8585
<Compile Include="ShortHistogram.cs" />
86+
<Compile Include="TimeStamp.cs" />
8687
<Compile Include="Utilities\ArrayExtensions.cs" />
8788
<Compile Include="Utilities\Bitwise.cs" />
8889
<Compile Include="LongHistogram.cs" />

src/HdrHistogram/OutputScalingFactor.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,4 @@ public static class OutputScalingFactor
3535
/// </summary>
3636
public static readonly double TimeStampToSeconds = Stopwatch.Frequency;
3737
}
38-
39-
public static class TimeStamp
40-
{
41-
public static long Seconds(int seconds)
42-
{
43-
return Stopwatch.Frequency*seconds;
44-
}
45-
46-
public static long Minutes(int minutes)
47-
{
48-
return Stopwatch.Frequency * minutes * 60L;
49-
}
50-
public static long Hours(int hours)
51-
{
52-
return Stopwatch.Frequency * hours * 60L * 60L;
53-
}
54-
}
5538
}

src/HdrHistogram/TimeStamp.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Diagnostics;
2+
3+
namespace HdrHistogram
4+
{
5+
/// <summary>
6+
/// Helper methods to get time periods based in system stopwatch units.
7+
/// </summary>
8+
public static class TimeStamp
9+
{
10+
/// <summary>
11+
/// Return a <see cref="long"/> representing the number system timer ticks that occur over the provided number of seconds.
12+
/// </summary>
13+
/// <param name="seconds">A number seconds to represent.</param>
14+
/// <returns>The number of system timer ticks that represent the <paramref name="seconds"/>.</returns>
15+
public static long Seconds(int seconds)
16+
{
17+
return Stopwatch.Frequency*seconds;
18+
}
19+
20+
/// <summary>
21+
/// Return a <see cref="long"/> representing the number system timer ticks that occur over the provided number of minutes.
22+
/// </summary>
23+
/// <param name="minutes">A number minutes to represent.</param>
24+
/// <returns>The number of system timer ticks that represent the <paramref name="minutes"/>.</returns>
25+
public static long Minutes(int minutes)
26+
{
27+
return Stopwatch.Frequency * minutes * 60L;
28+
}
29+
30+
/// <summary>
31+
/// Return a <see cref="long"/> representing the number system timer ticks that occur over the provided number of hours.
32+
/// </summary>
33+
/// <param name="hours">A number hours to represent.</param>
34+
/// <returns>The number of system timer ticks that represent the <paramref name="hours"/>.</returns>
35+
public static long Hours(int hours)
36+
{
37+
return Stopwatch.Frequency * hours * 60L * 60L;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)