Skip to content

Commit 1fde56a

Browse files
committed
benchmark project
1 parent c2f4d4c commit 1fde56a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

Starscript.Net.sln

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starscript.Net.Tests", "src
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starscript.Net.TestProgram", "src\TestProgram\Starscript.Net.TestProgram.csproj", "{3046ED02-73C4-49D7-A697-4995642D2921}"
88
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starscript.Net.Benchmarks", "src\Benchmarks\Starscript.Net.Benchmarks.csproj", "{6087079B-D22A-45C1-9AA6-999DAFFF6A6E}"
10+
EndProject
911
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
1012
ProjectSection(SolutionItems) = preProject
1113
README.md = README.md
1214
.github\workflows\main.yml = .github\workflows\main.yml
1315
EndProjectSection
1416
EndProject
15-
1617
Global
1718
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1819
Debug|Any CPU = Debug|Any CPU
@@ -31,5 +32,9 @@ Global
3132
{3046ED02-73C4-49D7-A697-4995642D2921}.Debug|Any CPU.Build.0 = Debug|Any CPU
3233
{3046ED02-73C4-49D7-A697-4995642D2921}.Release|Any CPU.ActiveCfg = Release|Any CPU
3334
{3046ED02-73C4-49D7-A697-4995642D2921}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{6087079B-D22A-45C1-9AA6-999DAFFF6A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{6087079B-D22A-45C1-9AA6-999DAFFF6A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{6087079B-D22A-45C1-9AA6-999DAFFF6A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{6087079B-D22A-45C1-9AA6-999DAFFF6A6E}.Release|Any CPU.Build.0 = Release|Any CPU
3439
EndGlobalSection
3540
EndGlobal

src/Benchmarks/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using BenchmarkDotNet.Running;
4+
using Starscript.Net.Benchmarks;
5+
6+
BenchmarkRunner.Run<StarscriptVsStringFormat>();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
12+
<ProjectReference Include="../Lib/Starscript.Net.csproj"/>
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace Starscript.Net.Benchmarks;
4+
5+
public class StarscriptVsStringFormat
6+
{
7+
public static StarscriptHypervisor Hypervisor { get; } = StarscriptHypervisor.Create().WithStandardLibrary();
8+
9+
public const string FormatSource = "FPS: {0}";
10+
public const string StarscriptSource = "FPS: {round(fps)}";
11+
12+
public static Script PrecompiledTestScript = Compiler.DirectCompile(StarscriptSource);
13+
14+
public StarscriptVsStringFormat()
15+
{
16+
Hypervisor.Set("fps", 59.68223);
17+
}
18+
19+
[Benchmark]
20+
public void StringFormat()
21+
{
22+
_ = string.Format(FormatSource, Math.Round(59.68223));
23+
}
24+
25+
[Benchmark]
26+
public void PrecompiledStarscript()
27+
{
28+
_ = PrecompiledTestScript.Execute(Hypervisor);
29+
}
30+
31+
[Benchmark]
32+
public void JitStarscript()
33+
{
34+
_ = Compiler.DirectCompile(StarscriptSource).Execute(Hypervisor);
35+
}
36+
}

0 commit comments

Comments
 (0)