Skip to content

Commit 0987bfe

Browse files
committed
Fixed some declaration bugs in HugeBuffer. Added VectorVsISPC benchmark. Added float data type.
1 parent 3c12513 commit 0987bfe

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

jemalloc.Api/HugeArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace jemalloc
66
{
7-
public class HugeArray<T> : HugeBuffer<T> where T : struct
7+
public class HugeArray<T> : HugeBuffer<T> where T : struct, IEquatable<T>
88
{
99
public HugeArray(ulong length, params T[] values) : base(length, values) { }
1010
}

jemalloc.Api/HugeBufferEnumerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace jemalloc
88
{
99
/// <summary>Enumerates the elements of a <see cref="HugeBuffer{T}"/>.</summary>
10-
public class HugeBufferEnumerator<T> : IEnumerator, IEnumerator<T> where T : struct
10+
public class HugeBufferEnumerator<T> : IEnumerator, IEnumerator<T> where T : struct, IEquatable<T>
1111
{
1212
/// <summary>The span being enumerated.</summary>
1313
private readonly HugeBuffer<T> _buffer;

jemalloc.Api/JemUtil.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Immutable;
66
using System.Numerics;
77
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
89

910
namespace jemalloc
1011
{
@@ -179,6 +180,31 @@ public static Tuple<double, string> PrintBytesToTuple(double bytes, string suffi
179180
string[] s = PrintBytes(bytes, suffix).Split(' ');
180181
return new Tuple<double, string>(Double.Parse(s[0]), s[1]);
181182
}
183+
184+
public static ulong GetWindowsThreadCycles()
185+
{
186+
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
187+
{
188+
throw new PlatformNotSupportedException();
189+
}
190+
191+
if (__Internal.QueryThreadCycleTime(__Internal.PseudoHandle, out ulong cycles))
192+
{
193+
return cycles;
194+
}
195+
else
196+
{
197+
throw new System.ComponentModel.Win32Exception();
198+
}
199+
200+
}
201+
202+
public partial struct __Internal
203+
{
204+
[DllImport("kernel32.dll", SetLastError = true)]
205+
internal static extern bool QueryThreadCycleTime(in IntPtr hThread, out ulong cycles);
206+
internal static readonly IntPtr PseudoHandle = (IntPtr)(-2);
207+
}
182208
#endregion
183209

184210
#region Fields

jemalloc.Benchmarks/Benchmarks/HugeNativeVsManagedArray.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override void GlobalSetup()
2121
DebugInfoThis();
2222
base.GlobalSetup();
2323
Info($"Unmanaged array size is {ArraySize}.");
24-
Info($"Managed array size is {ArraySize}.");
24+
Info($"Managed array size is {MaxManagedArraySize}.");
2525
T[] managedArray = new T[MaxManagedArraySize];
2626
SetValue("managedArray", managedArray);
2727
HugeArray<T> hugeArray = new HugeArray<T>(ArraySize);
@@ -49,7 +49,7 @@ public override void GlobalSetup()
4949
[BenchmarkCategory("Fill")]
5050
public void FillManagedArray()
5151
{
52-
InfoThis();
52+
DebugInfoThis();
5353
T[] managedArray = GetValue<T[]>("managedArray");
5454
T fill = GetValue<T>("fill");
5555
for (int i = 0; i < managedArray.Length; i++)
@@ -62,7 +62,7 @@ public void FillManagedArray()
6262
[BenchmarkCategory("Fill")]
6363
public void FillHugeNativeArray()
6464
{
65-
InfoThis();
65+
DebugInfoThis();
6666
HugeArray<T> hugeArray = GetValue<HugeArray<T>>("hugeArray");
6767
T fill = GetValue<T>("fill");
6868
hugeArray.Fill(fill);
@@ -72,7 +72,7 @@ public void FillHugeNativeArray()
7272
[BenchmarkCategory("Fill")]
7373
public void FillManagedArrayWithCreate()
7474
{
75-
InfoThis();
75+
DebugInfoThis();
7676
T[] managedArray = new T[ArraySize];
7777
T fill = GetValue<T>("fill");
7878
for (int i = 0; i < managedArray.Length; i++)
@@ -138,6 +138,7 @@ public void CreateHugeNativeArray()
138138
[BenchmarkCategory("Arithmetic")]
139139
public void ArithmeticMultiplyManagedArray()
140140
{
141+
DebugInfoThis();
141142
T mul = GetValue<T>("mul");
142143
T fill = GetValue<T>("fill");
143144
T[] managedArray = GetValue<T[]>("managedArray");
@@ -153,6 +154,7 @@ public void ArithmeticMultiplyManagedArray()
153154
[BenchmarkCategory("Arithmetic")]
154155
public void ArithmeticMultiplyHugeNativeArray()
155156
{
157+
DebugInfoThis();
156158
T mul = GetValue<T>("mul");
157159
T fill = GetValue<T>("fill");
158160
HugeArray<T> hugeArray = GetValue<HugeArray<T>>("hugeArray");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace jemalloc.Benchmarks.Benchmarks
6+
{
7+
public class VectorVsISPC : JemBenchmark<float, int>
8+
{
9+
}
10+
}

jemalloc.Cli/Options.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Options
2424
[Option('l', "int64", Required = false, HelpText = "Use Int64 long integer as the underlying data type.", SetName = "type")]
2525
public bool Int64 { get; set; }
2626

27+
[Option('f', "float", Required = false, HelpText = "Use single-precision floating point as the underlying data type.", SetName = "type")]
28+
public bool Float { get; set; }
29+
2730
[Option('m', "double", Required = false, HelpText = "Use double-precision floating point as the underlying data type.", SetName = "type")]
2831
public bool Double { get; set; }
2932

jemalloc.Cli/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ static void Benchmark(Options o)
278278
{
279279
Benchmark<Int64>();
280280
}
281+
else if (o.Float)
282+
{
283+
Benchmark<Single>();
284+
}
281285
else if (o.Double)
282286
{
283287
Benchmark<Double>();

0 commit comments

Comments
 (0)