Skip to content

Commit

Permalink
Add Corvus implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Sep 29, 2024
1 parent f9c6036 commit edbfc0d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,20 @@ dist/results/go-jsonschema/%: \
schemas/%/instances.jsonl \
| dist/results/go-jsonschema
@$(call docker_run,go-jsonschema,/workspace/$(dir $(word 2,$^)))

# DOTNET / CORVUS

implementations/corvus/.dockertimestamp: \
implementations/corvus/bench.csproj \
implementations/corvus/Program.cs \
implementations/corvus/generate-and-run.sh \
implementations/corvus/Dockerfile
docker build -t jsonschema-benchmark/corvus implementations/corvus
touch $@

dist/results/corvus/%: \
implementations/corvus/.dockertimestamp \
schemas/%/schema.json \
schemas/%/instances.jsonl \
| dist/results/corvus
@$(call docker_run,corvus,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
6 changes: 6 additions & 0 deletions implementations/corvus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0

COPY . /app
RUN dotnet tool install --global Corvus.Json.JsonSchema.TypeGeneratorTool --version 3.1.1
ENTRYPOINT ["/app/generate-and-run.sh"]
CMD []
24 changes: 24 additions & 0 deletions implementations/corvus/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Corvus.Json;
using System.Diagnostics;
using System.Linq;

// Read and parse all instances
var lines = File.ReadLines(args[0]);
var docs = lines.Select(l => JSB.Schema.Parse(l));

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();

// Loop and validate all instances
var valid = true;
foreach (var doc in docs) {
var result = doc.Validate(ValidationContext.ValidContext, ValidationLevel.Flag);
valid = valid && result.IsValid;
}

stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;

// Output file time and exit
Console.WriteLine(ts.TotalNanoseconds);
Environment.Exit(valid ? 0 : 1);
14 changes: 14 additions & 0 deletions implementations/corvus/bench.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>
<PackageReference Include="Corvus.Json.ExtendedTypes" Version="3.1.1" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions implementations/corvus/generate-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

SCHEMA=$1
INSTANCES=$2

~/.dotnet/tools/generatejsonschematypes --rootNamespace JSB --rootPath='#' --useSchema Draft4 --outputPath /app "$1" > /dev/null

cd app
dotnet build --configuration=Release > /dev/null || exit 1
rm -f Schema*.cs
/app/bin/Release/net8.0/bench "$2"
exit $?
6 changes: 6 additions & 0 deletions implementations/corvus/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -o errexit
set -o nounset

grep -Eo '\--version .*$' implementations/corvus/Dockerfile | cut -d' ' -f2

0 comments on commit edbfc0d

Please sign in to comment.