Skip to content

Commit

Permalink
Fix BuiltInNode bug; add Benchmarks project
Browse files Browse the repository at this point in the history
  • Loading branch information
G3Kappa committed May 21, 2024
1 parent 4c6e7b8 commit d04bfde
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 15 deletions.
14 changes: 14 additions & 0 deletions Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Ergo\Ergo.csproj" />
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Ergo.Facade;
using Ergo.Interpreter;
using Ergo.Lang;
using Ergo.Runtime;
using System.Diagnostics;

var facade = ErgoFacade.Standard;

int N_BENCHMARKS = 100;
var times = new List<string[]>();

for (int i = 0; i < N_BENCHMARKS; i++)
{
var interpreter = ErgoBenchmarks.MeasureInterpreterCreation(facade);
var scope = ErgoBenchmarks.MeasureInterpreterScopeCreation(interpreter.Value);
var kb = ErgoBenchmarks.MeasureKnowledgeBaseCreation(scope.Value);
var vm = ErgoBenchmarks.MeasureSpinUpTime(facade, kb.Value);
times.Add([interpreter.Str, scope.Str, kb.Str, vm.Str]);
}

var shell = facade.BuildShell();
shell.WriteTable(["Interpreter", "Int. Scope", "KnowledgeBase", "VM"], times.ToArray());


public sealed class ErgoBenchmarks
{
public static Measured<ErgoInterpreter> MeasureInterpreterCreation(ErgoFacade facade)
{
return Measured.Measure(() =>
{
return facade.BuildInterpreter();
});
}
public static Measured<InterpreterScope> MeasureInterpreterScopeCreation(ErgoInterpreter interpreter)
{
return Measured.Measure(() =>
{
return interpreter.CreateScope();
});
}
public static Measured<KnowledgeBase> MeasureKnowledgeBaseCreation(InterpreterScope scope)
{
return Measured.Measure(() =>
{
return scope.BuildKnowledgeBase();
});
}
public static Measured<ErgoVM> MeasureSpinUpTime(ErgoFacade facade, KnowledgeBase kb)
{
return Measured.Measure(() =>
{
return facade.BuildVM(kb);
});
}
}
public static class Measured
{
public static Measured<T> Measure<T>(Func<T> get)
{
var sw = new Stopwatch();
sw.Start();
var ret = get();
sw.Stop();
return new(sw.Elapsed, ret);
}
}
public readonly record struct Measured<T>(TimeSpan Duration, T Value)
{
public string Str => Duration.TotalSeconds.ToString("0.0000");
}
20 changes: 20 additions & 0 deletions Ergo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTests", "XUnitTests\XU
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ErgoLS", "ErgoLS\ErgoLS.csproj", "{E0545F99-556F-4F6D-8AC0-9C583948E2B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{8A83EC4A-8924-4C6B-87D5-E69330F6A503}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -81,6 +83,24 @@ Global
{E0545F99-556F-4F6D-8AC0-9C583948E2B7}.Release|arm64.Build.0 = Release|Any CPU
{E0545F99-556F-4F6D-8AC0-9C583948E2B7}.Release|x86.ActiveCfg = Release|Any CPU
{E0545F99-556F-4F6D-8AC0-9C583948E2B7}.Release|x86.Build.0 = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|arm64.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|arm64.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|x86.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Debug|x86.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|Any CPU.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|Any CPU.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|arm64.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|arm64.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|x86.ActiveCfg = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Diagnostics|x86.Build.0 = Debug|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|Any CPU.Build.0 = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|arm64.ActiveCfg = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|arm64.Build.0 = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|x86.ActiveCfg = Release|Any CPU
{8A83EC4A-8924-4C6B-87D5-E69330F6A503}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Ergo/Interpreter/InterpreterScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private InterpreterScope(
VisibleOperators = GetOperators().ToImmutableArray();
}

public KnowledgeBase BuildKnowledgeBase(CompilerFlags vmFlags, Action<KnowledgeBase> beforeCompile = null)
public KnowledgeBase BuildKnowledgeBase(CompilerFlags vmFlags = CompilerFlags.Default, Action<KnowledgeBase> beforeCompile = null)
{
var kb = new KnowledgeBase(this);
foreach (var builtIn in VisibleBuiltIns.Values)
Expand Down
2 changes: 1 addition & 1 deletion Ergo/Lang/Compiler/Nodes/Goals/BuiltInNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ErgoVM.Op SetArgs(ImmutableArray<ITerm> args) => vm =>

public override ErgoVM.Op Compile() => vm =>
{
SetArgs(Args);
SetArgs(Args)(vm);
vm.SetFlag(VMFlags.ContinuationIsDet, IsContinuationDet);
vm.LogState(Explain(false));
CompiledBuiltIn(vm);
Expand Down
1 change: 1 addition & 0 deletions ErgoVSIX/ErgoLS/Ergo.runtimeconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "8.0.0-rc.1.23419.4"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
Expand Down
1 change: 1 addition & 0 deletions ErgoVSIX/ErgoLS/ErgoLS.runtimeconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "8.0.0-rc.1.23419.4"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
Expand Down
1 change: 1 addition & 0 deletions ErgoVSIX/ErgoLS/ergo/stdlib/Ergo.runtimeconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "8.0.0-rc.1.23419.4"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
Expand Down
1 change: 1 addition & 0 deletions ErgoVSIX/ErgoLS/ergo/stdlib/ErgoLS.runtimeconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "8.0.0-rc.1.23419.4"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
Expand Down
20 changes: 7 additions & 13 deletions XUnitTests/ergo/user/fiero/ui_test.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
% Do not modify unless you know what you are doing.

:- module(ui_test, []).
:- op(35, xfy, ['</>']).

% COMPONENTS

row: (
row: (
cell: label { text: 'we' }
),
row: (
col: (
cell: label { text: 'we' }
),
col: (
cell: layout {}
)
)
).
my_component </>
(row </> label{}),
(row </>
(col </> label{}),
(col </> layout{}))
.

0 comments on commit d04bfde

Please sign in to comment.