-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
61 lines (52 loc) · 2.02 KB
/
Program.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using ProjectCeilidh.NativeTK.Attributes;
namespace ProjectCeilidh.NativeTK.Benchmark
{
public class Program
{
[CoreJob]
[RankColumn, MedianColumn]
public class Benchmark
{
private static readonly ITestBinding IndirectBinding = BindingFactory.GetFactoryForBindingType(NativeBindingType.Indirect).CreateBinding<ITestBinding>();
private static readonly ITestBinding StaticBinding = BindingFactory.GetFactoryForBindingType(NativeBindingType.Static).CreateBinding<ITestBinding>();
[Benchmark]
public void Indirect()
{
var ptr = IndirectBinding.GlobalAlloc(0, (IntPtr) 1024);
IndirectBinding.GlobalFree(ptr);
}
[Benchmark]
public void Static()
{
var ptr = StaticBinding.GlobalAlloc(0, (IntPtr)1024);
StaticBinding.GlobalFree(ptr);
}
[Benchmark(Baseline = true)]
public void Baseline()
{
var ptr = GlobalAlloc(0, (IntPtr)1024);
GlobalFree(ptr);
}
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr GlobalAlloc(uint uFlags, IntPtr dwBytes);
[DllImport("Kernel32", CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr GlobalFree(IntPtr hMem);
}
private static void Main()
{
BenchmarkRunner.Run<Benchmark>();
}
[NativeLibraryContract("kernel32")]
public interface ITestBinding
{
[NativeImport(CallingConvention = CallingConvention.Winapi)]
IntPtr GlobalAlloc(uint uFlags, IntPtr dwBytes);
[NativeImport(CallingConvention = CallingConvention.Winapi)]
IntPtr GlobalFree(IntPtr hMem);
}
}
}