Skip to content

Commit 1c6f7f7

Browse files
EntityFXEntityFX
authored andcommitted
Added blazor benchmark variant
1 parent df6607b commit 1c6f7f7

34 files changed

Lines changed: 1418 additions & 8 deletions

src/dotnet/EntityFX.NetBenchamarks.Core/Dhrystone/Dhrystone2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CheckRecord
4242

4343
public Dhrystone2(bool printToConsole)
4444
{
45-
output = new Writer(null);
45+
output = WriterFactory.Build();
4646
output.UseConsole = printToConsole;
4747
}
4848

src/dotnet/EntityFX.NetBenchamarks.Core/Generic/MemoryBenchmarkBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public abstract class MemoryBenchmarkBase<TResult> : BenchmarkBase<TResult>
99
{
1010
private Random random;
1111

12-
protected IWriter localWriter = new Writer(null);
12+
protected IWriter localWriter = WriterFactory.Build();
1313

1414
#if PocketPC
1515
private Dictionary<string, int> intMemTests = new Dictionary<string, int>

src/dotnet/EntityFX.NetBenchamarks.Core/Generic/RandomMemoryBenchmarkBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class RandomMemoryBenchmarkBase<TResult> : BenchmarkBase<TResult
3333

3434
private Random random;
3535

36-
protected IWriter localWriter = new Writer(null);
36+
protected IWriter localWriter = WriterFactory.Build();
3737

3838
public RandomMemoryBenchmarkBase(bool printToConsole, IWriter writer)
3939
:base(writer)

src/dotnet/EntityFX.NetBenchamarks.Core/Linpack/Linpack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Linpack
1313

1414
public Linpack(bool printToConsole)
1515
{
16-
output = new Writer(null);
16+
output = WriterFactory.Build();
1717
this.output.UseConsole = printToConsole;
1818
}
1919

src/dotnet/EntityFX.NetBenchamarks.Core/Scimark2/Scimark2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Scimark2
99

1010
public Scimark2(bool printToConsole)
1111
{
12-
output = new Writer(null);
12+
output = WriterFactory.Build();
1313
output.UseConsole = printToConsole;
1414
}
1515

src/dotnet/EntityFX.NetBenchamarks.Core/Whetstone/Whetstone.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Whetstone
2222

2323
public Whetstone(bool printToConsole)
2424
{
25-
output = new Writer(null);
25+
output = WriterFactory.Build();
2626
output.UseConsole = printToConsole;
2727
}
2828

src/dotnet/EntityFX.NetBenchamarks.Core/Whetstone/WhetstoneDouble.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class WhetstoneDouble
2222

2323
public WhetstoneDouble(bool printToConsole)
2424
{
25-
output = new Writer(null);
25+
output = WriterFactory.Build();
2626
output.UseConsole = printToConsole;
2727
}
2828

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
namespace EntityFX.NetBenchmark.Core
3+
{
4+
public static class WriterFactory
5+
{
6+
public static IWriter Build()
7+
{
8+
return Builder?.Invoke() ?? new Writer(null);
9+
}
10+
11+
public static Func<IWriter> Builder;
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using EntityFX.NetBenchmark.Core;
2+
using System;
3+
using System.IO;
4+
5+
namespace EntityFX.NetBenchmark.Blazor
6+
{
7+
public class BlazorWriter : IDisposable, IWriter
8+
{
9+
private TextWriter writer = new StringWriter();
10+
11+
public bool UseConsole { get; set; }
12+
13+
public bool UseFile { get; set; }
14+
15+
public event EventHandler<string> TextWrite;
16+
17+
private string consoleBuffer = string.Empty;
18+
19+
20+
public BlazorWriter()
21+
{
22+
UseConsole = true;
23+
}
24+
25+
public string Output
26+
{
27+
get
28+
{
29+
return writer.ToString();
30+
}
31+
}
32+
33+
34+
public void WriteLine(string format, params object[] args)
35+
{
36+
Write(ConsoleColor.Gray, format, args);
37+
WriteLine();
38+
}
39+
40+
public void WriteLine()
41+
{
42+
writer.WriteLine();
43+
if (UseConsole) Console.WriteLine();
44+
TextWrite?.Invoke(this, "\n");
45+
}
46+
47+
public void WriteHeader(string format, params object[] args)
48+
{
49+
writer.WriteLine(format, args);
50+
Write(ConsoleColor.Cyan, format, args);
51+
WriteLine();
52+
}
53+
54+
public void Write(string format, params object[] args)
55+
{
56+
Write(ConsoleColor.Gray, format, args);
57+
}
58+
59+
public void Write(ConsoleColor color, string format, params object[] args)
60+
{
61+
var text = string.Format(format, args);
62+
writer.Write(text);
63+
if (UseConsole)
64+
{
65+
Console.Write(text);
66+
}
67+
TextWrite?.Invoke(this, text);
68+
}
69+
70+
public void WriteValue(string format, params object[] args)
71+
{
72+
Write(ConsoleColor.Green, format, args);
73+
}
74+
75+
76+
public void WriteTitle(string format, params object[] args)
77+
{
78+
Write(ConsoleColor.White, format, args);
79+
}
80+
81+
public void Dispose()
82+
{
83+
writer.Flush();
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)