|
# Nix flake, which generates document above |
|
|
|
{ |
|
description = "Jrsonnet benchmark"; |
|
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
|
inputs.flake-utils.url = "github:numtide/flake-utils"; |
|
inputs.jrsonnet.url = "github:CertainLach/jrsonnet"; |
|
|
|
outputs = { self, nixpkgs, flake-utils, jrsonnet }: |
|
|
|
flake-utils.lib.eachDefaultSystem (system: |
|
let pkgs = nixpkgs.legacyPackages.${system}; |
|
in { |
|
defaultPackage = pkgs.stdenv.mkDerivation { |
|
name = "jrsonnet-benchmark"; |
|
|
|
buildInputs = [ |
|
jrsonnet.outputs.defaultPackage.${system} |
|
|
|
pkgs.rustfmt |
|
pkgs.cargo |
|
|
|
pkgs.hyperfine |
|
|
|
pkgs.jsonnet |
|
(pkgs.callPackage pkgs.stdenv.mkDerivation { |
|
name = "sjsonnet"; |
|
src = pkgs.fetchurl { |
|
url = |
|
"https://github.com/databricks/sjsonnet/releases/download/0.2.6/sjsonnet.jar"; |
|
sha256 = "076fgpj1kmqix157c8cqz617z6r99nwmy125p7gpi8nnrxc90bvs"; |
|
}; |
|
unpackPhase = "true"; |
|
buildInputs = |
|
[ pkgs.adoptopenjdk-hotspot-bin-8 pkgs.makeWrapper ]; |
|
installPhase = '' |
|
mkdir -p $out/bin $out/lib |
|
cp $src $out/lib/sjsonner.jar |
|
makeWrapper ${pkgs.adoptopenjdk-hotspot-bin-8}/bin/java $out/bin/sjsonnet --add-flags "-jar $out/lib/sjsonner.jar" |
|
''; |
|
separateDebugInfo = false; |
|
}) |
|
(pkgs.callPackage pkgs.stdenv.mkDerivation { |
|
name = "gojsonnet"; |
|
unpackPhase = "true"; |
|
buildInputs = [ pkgs.go-jsonnet ]; |
|
installPhase = '' |
|
mkdir -p $out/bin |
|
echo "Test" |
|
cp ${pkgs.go-jsonnet}/bin/jsonnet $out/bin/gojsonnet |
|
''; |
|
separateDebugInfo = false; |
|
}) |
|
]; |
|
src = pkgs.fetchFromGitHub { |
|
owner = "google"; |
|
repo = "jsonnet"; |
|
rev = "2991580ddae4027384502cfe11a31bd032d58247"; |
|
sha256 = "15csk6bhvjkjy3fg3g06pg5pds41lgfrgnxr435s8cyy6m1bjr23"; |
|
}; |
|
buildPhase = "true"; |
|
installPhase = let |
|
bench = name: |
|
{ go ? true, scala ? true, cpp ? true, large ? false |
|
, comment ? null }: |
|
let path = "${name}.jsonnet"; |
|
in '' |
|
hyperfine --style basic --export-markdown 'result.md' 'jrsonnet ${path}' ${ |
|
if go then |
|
"'gojsonnet ${if large then "-s 200000" else ""} ${path}'" |
|
else |
|
"" |
|
} ${ |
|
if cpp then |
|
"'jsonnet ${if large then "-s 200000" else ""} ${path}'" |
|
else |
|
"" |
|
} ${if scala then "'sjsonnet ${path}'" else ""} |
|
echo '## ${name}' >> $out |
|
${if comment != null then '' |
|
echo >> $out |
|
echo "${comment}" >> $out |
|
'' else '' |
|
echo >> $out |
|
''} |
|
|
|
cat result.md >> $out |
|
echo >> $out |
|
''; |
|
in '' |
|
echo "# Benchmark results" > $out |
|
echo "" >> $out |
|
|
|
cd perf_tests |
|
|
|
${bench "large_string_join" { }} |
|
${bench "large_string_template" { |
|
go = false; |
|
comment = '' |
|
> Golang overflows OS stack on this test |
|
''; |
|
}} |
|
${bench "realistic1" { }} |
|
${bench "realistic2" { }} |
|
|
|
cd ../benchmarks |
|
|
|
jrsonnet -S gen_big_object.jsonnet > bench.05.gen.jsonnet |
|
|
|
${bench "bench.01" { |
|
scala = false; |
|
comment = '' |
|
> Scala impl fails with obscure exception in this test |
|
''; |
|
}} |
|
${bench "bench.02" { }} |
|
${bench "bench.03" { }} |
|
${bench "bench.04" { }} |
|
${bench "bench.05.gen" { }} |
|
${bench "bench.06" { |
|
scala = false; |
|
comment = '' |
|
> std.reverse is not implemented in scala |
|
''; |
|
}} |
|
${bench "bench.07" { |
|
large = true; |
|
scala = false; |
|
comment = '' |
|
> C++ and golang impl overflows stack in this test with default settings |
|
> Scala impl fails with stack overflow in this test |
|
''; |
|
}} |
|
${bench "bench.08" { }} |
|
''; |
|
}; |
|
}); |
|
|
|
} |