-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathProgram.cs
86 lines (76 loc) · 2.23 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
using Wasmtime;
namespace Simple
{
[Config(typeof(Config))]
public class Benchmark
{
private class Config : ManualConfig
{
public Config()
{
AddJob(Job.MediumRun
.WithLaunchCount(1)
.WithToolchain(InProcessEmitToolchain.Instance)
.WithId("InProcess"));
}
}
public Benchmark()
{
_engine = new Engine();
_module = Module.FromText(
_engine,
"hello",
@"
(module
(type $t0 (func))
(import """" ""hello"" (func $.hello (type $t0)))
(func $run
call $.hello
)
(export ""run"" (func $run))
)"
);
}
[Benchmark]
public void SayHello()
{
using var linker = new Linker(_engine);
using var store = new Store(_engine);
linker.Define("", "hello", Function.FromCallback(store, () => { }));
linker.Define("", "memory", new Memory(store, 3));
var instance = linker.Instantiate(store, _module);
var run = instance.GetFunction("run")!.WrapAction();
if (run == null)
{
throw new InvalidOperationException();
}
run.Invoke();
}
private readonly Engine _engine;
private readonly Module _module;
}
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<Benchmark>();
var report = summary[summary.BenchmarksCases.Single(c => c.Descriptor.Type == typeof(Benchmark))];
if (!(report is null))
{
if (report.ExecuteResults.All(r => r.ExitCode == 0))
{
return;
}
}
Console.Error.WriteLine("Benchmark failed.");
Environment.Exit(1);
}
}
}