Skip to content

Commit

Permalink
update benchmark to load everything outside of test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsdennis committed Jun 20, 2023
1 parent d4aea25 commit 114428e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 0 additions & 2 deletions JsonSchema.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Program
{
static void Main(string[] args)
{
TestSuiteRunner.LoadRemoteSchemas();

#if DEBUG
IConfig config = new DebugBuildConfig();
config.WithOptions(ConfigOptions.DisableOptimizationsValidator);
Expand Down
13 changes: 10 additions & 3 deletions JsonSchema.Benchmark/Suite/TestSuiteRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ private static IEnumerable<TestCollection> GetTests(string draftFolder)
}
}

public static void LoadRemoteSchemas()
private static void LoadRemoteSchemas()
{
// ReSharper disable once HeuristicUnreachableCode
var remotesPath = Path.Combine(Directory.GetCurrentDirectory(), _remoteSchemasPath)
var remotesPath = Path.Combine(Directory.GetCurrentDirectory(), _benchmarkOffset, _remoteSchemasPath)
.AdjustForPlatform();
if (!Directory.Exists(remotesPath)) throw new Exception("Cannot find remotes folder");

Expand All @@ -105,6 +105,13 @@ public static void LoadRemoteSchemas()
}
}

[GlobalSetup]
public void BenchmarkSetup()
{
LoadRemoteSchemas();
_ = GetAllTests();
}

[Benchmark]
public int RunSuite()
{
Expand All @@ -127,7 +134,7 @@ private static void Benchmark(TestCollection collection, TestCase test)
{
if (!InstanceIsDeserializable(test.Data)) return;

var result = collection.Schema.Evaluate(test.Data, collection.Options);
_ = collection.Schema.Evaluate(test.Data, collection.Options);
}

private static bool InstanceIsDeserializable(in JsonNode? testData)
Expand Down

0 comments on commit 114428e

Please sign in to comment.