-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix BuiltInNode bug; add Benchmarks project
- Loading branch information
G3Kappa
committed
May 21, 2024
1 parent
4c6e7b8
commit d04bfde
Showing
10 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters