difftreelog
ci reenable scala for quick benchmarking
in: master
1 file changed
nix/benchmarks.nixdiffbeforeafterboth1{2 lib,3 runCommand,4 jsonnet-bundler,5 cacert,6 stdenv,7 fetchFromGitHub,8 go-jsonnet,9 sjsonnet,10 cpp-jsonnet,11 rsjsonnet,12 hyperfine,13 quick ? false,14 jrsonnetVariants,15}:16with lib;17let18 inherit (cpp-jsonnet) jsonnetBench;19 inherit (go-jsonnet) goJsonnetBench;20 graalvmBench = fetchFromGitHub {21 owner = "oracle";22 repo = "graal";23 rev = "bc305df3fe587960f7635f0185571500e5988475";24 hash = "sha256-4EKB1b2o4/qtYQ+nqbbs621OJrtjApsAWEBcw5EjrYc=";25 };26 kubePrometheusBench =27 let28 src = fetchFromGitHub {29 owner = "prometheus-operator";30 repo = "kube-prometheus";31 rev = "d3889807798d1697ea0691f10caf1b6a1997a8bd";32 hash = "sha256-TeYWHzoZAmDp2PzT7EH8XRUcvb3tR8Qfxel7o2QBvIM=";33 };34 in35 runCommand "kube-prometheus-vendor"36 {37 outputHash = "sha256-AGc0dHlD/Ld7I5b1+gOotzJkYrn+bB1VjISdD5NITtw=";38 outputHashMode = "recursive";39 buildInputs = [ cacert ];40 }41 ''42 mkdir -p $out43 cp -r ${src}/* $out/44 cd $out45 chmod u+w jsonnetfile.lock.json46 mkdir vendor47 ${jsonnet-bundler}/bin/jb install48 '';4950 # Removes outsiders from the output51 # Useful when comparing performance of different jrsonnet releases52 skipSlow = if quick then "slow benchmark, but only quick requested" else "";53in54stdenv.mkDerivation {55 name = "benchmarks";56 # __impure = true; # not supported by hercules-ci57 unpackPhase = "true";5859 buildInputs = [60 sjsonnet61 cpp-jsonnet62 rsjsonnet63 go-jsonnet6465 hyperfine66 ];6768 installPhase =69 let70 mkBench =71 {72 name,73 path,74 omitSource ? false,75 pathIsGenerator ? false,76 skipRustAlternative ? "",77 skipScala ? "",78 skipCpp ? "",79 skipGo ? "",80 vendor ? "",81 }:82 ''83 echo >> $out84 echo "=== ${name}" >> $out85 echo >> $out86 ${optionalString(skipRustAlternative!="")''87 echo "> Note: No results for Rust (alternative), ${skipRustAlternative}" >> $out88 echo >> $out89 ''}90 ${optionalString(skipGo!="")''91 echo "> Note: No results for Go, ${skipGo}" >> $out92 echo >> $out93 ''}94 ${optionalString(skipScala!="")''95 echo "> Note: No results for Scala (native)/Scala (GraalVM), ${skipScala}" >> $out96 echo >> $out97 ''}98 ${optionalString(skipCpp!="")''99 echo "> Note: No results for C++, ${skipCpp}" >> $out100 echo >> $out101 ''}102 ${optionalString(!quick&&!omitSource)''103 echo ".Source" >> $out104 echo "[%collapsible]" >> $out105 echo "====" >> $out106 echo "[source,jsonnet]" >> $out107 echo "----" >> $out108 ${optionalStringpathIsGenerator"echo \"// Generator source\" >> $out"}109 cat ${path} >> $out110 echo >> $out111 echo "----" >> $out112 echo "====" >> $out113 echo >> $out114 ''}115 path=${path}116 ${optionalStringpathIsGenerator''117 go-jsonnet $path > generated.jsonnet118 path=generated.jsonnet119 ''}120 hyperfine -N -w4 -m20 --output=pipe --style=basic --export-asciidoc result.adoc \121 ${122 concatStringsSep" "(123forEachjrsonnetVariants(124variant125"\"${variant.drv}/bin/jrsonnet $path${optionalString(vendor!="")" -J${vendor}"}\" -n \"Rust${126 ifvariant.name!=""then" (${variant.name})"else""127 }\""128)129)130 } \131 ${132 optionalString(skipRustAlternative=="")133"\"rsjsonnet $path${134 optionalString(vendor!="")" -J ${vendor}"135 }\" -n \"Rust (alternative, rsjsonnet)\""136 } \137 ${138 optionalString(skipGo=="")139"\"go-jsonnet $path${optionalString(vendor!="")" -J ${vendor}"}\" -n \"Go\""140 } \141 ${142 optionalString(skipScala=="")143"\"sjsonnet-native $path${optionalString(vendor!="")" -J ${vendor}"}\" -n \"Scala (native)\""144 } \145 ${146 147 148 optionalString(skipScala==""&&stdenv.hostPlatform.system!="aarch64-linux")149"\"sjsonnet-graalvm $path${optionalString(vendor!="")" -J ${vendor}"}\" -n \"Scala (GraalVM)\""150 } \151 ${optionalString(skipCpp=="")152"\"jsonnet $path${optionalString(vendor!="")" -J ${vendor}"}\" -n \"C++\""153 }154 cat result.adoc >> $out155 '';156 in157 ''158 set -oux159 ulimit -s unlimited160161 temp=$(mktemp -d)162 cd $temp163164 touch $out165 ${optionalString(!quick)''166 cat ${} >> $out167 echo >> $out168169 echo "CPU: $(grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2 | xargs), $(grep -c '^processor' /proc/cpuinfo) threads" >> $out170 echo >> $out171172 echo ".Tested versions" >> $out173 echo "[%collapsible]" >> $out174 echo "====" >> $out175 echo "* Go: $(go-jsonnet --version)" >> $out176 echo "* C++: $(jsonnet --version)" >> $out177 echo "* Scala (native/GraalVM): $(sjsonnet-native 2>&1 | grep -oP 'Sjsonnet \S+')" >> $out178 echo "* Rust (alternative): rsjsonnet ${rsjsonnet.version} (${rsjsonnet.src.rev})" >> $out179 ${concatStringsSep"\n"(180forEachjrsonnetVariants(181variant182"echo \"* Rust${183 ifvariant.name!=""then" (${variant.name})"else""184 }: $(${variant.drv}/bin/jrsonnet --version 2>&1)\" >> $out"185)186)}187 echo "====" >> $out188 echo >> $out189 ''}190 echo "== Real world" >> $out191 ${mkBench{192name="Graalvm CI";193path="${graalvmBench}/ci.jsonnet";194omitSource=true;195skipCpp="takes longer than a hour";196skipGo=skipSlow;197skipScala=skipSlow;198}}199 ${mkBench{200name="Kube-prometheus manifests";201vendor="${kubePrometheusBench}/vendor";202path="${kubePrometheusBench}/example.jsonnet";203omitSource=true;204skipCpp="too slow, takes hours, skews results";205skipGo=skipSlow;206skipScala=skipSlow;207}}208209 echo >> $out210 echo "== Benchmarks from C++ jsonnet (/perf_tests)" >> $out211 ${mkBench{212name="Large string join";213path="${jsonnetBench}/perf_tests/large_string_join.jsonnet";214skipScala=skipSlow;215}}216 ${mkBench{217name="Large string template";218omitSource=true;219path="${jsonnetBench}/perf_tests/large_string_template.jsonnet";220skipGo="fails with os stack size exhausion";221skipCpp="too slow, takes hours, skews results";222skipScala=skipSlow;223}}224 ${mkBench{225name="Realistic 1";226path="${jsonnetBench}/perf_tests/realistic1.jsonnet";227skipGo=skipSlow;228skipCpp="too slow, takes hours, skews results";229skipScala=skipSlow;230}}231 ${mkBench{232name="Realistic 2";233path="${jsonnetBench}/perf_tests/realistic2.jsonnet";234skipGo=skipSlow;235skipCpp="too slow, takes hours, skews results";236skipScala=skipSlow;237}}238239 echo >> $out240 echo "== Benchmarks from C++ jsonnet (/benchmarks)" >> $out241 ${mkBench{242name="Tail call";243path="${jsonnetBench}/benchmarks/bench.01.jsonnet";244skipScala=skipSlow;245}}246 ${mkBench{247name="Inheritance recursion";248path="${jsonnetBench}/benchmarks/bench.02.jsonnet";249skipCpp=skipSlow;250skipGo=skipSlow;251}}252 ${mkBench{253name="Simple recursive call";254path="${jsonnetBench}/benchmarks/bench.03.jsonnet";255skipScala=skipSlow;256skipGo=skipSlow;257}}258 ${mkBench{259name="Foldl string concat";260path="${jsonnetBench}/benchmarks/bench.04.jsonnet";261skipCpp=skipSlow;262skipScala=skipSlow;263}}264 ${mkBench{265name="Array sorts";266path="${jsonnetBench}/benchmarks/bench.06.jsonnet";267skipCpp=skipSlow;268}}269 ${mkBench{270name="Lazy array";271path="${jsonnetBench}/benchmarks/bench.07.jsonnet";272skipGo=skipSlow;273}}274 ${mkBench{275name="Inheritance function recursion";276path="${jsonnetBench}/benchmarks/bench.08.jsonnet";277skipCpp=skipSlow;278skipScala=skipSlow;279}}280 ${mkBench{281name="String strips";282path="${jsonnetBench}/benchmarks/bench.09.jsonnet";283skipCpp="too slow, takes hours, skews results";284skipScala=skipSlow;285}}286 ${mkBench{287name="Big object";288path="${jsonnetBench}/benchmarks/gen_big_object.jsonnet";289pathIsGenerator=true;290skipScala=skipSlow;291}}292293 echo >> $out294 echo "== Benchmarks from Go jsonnet (builtins)" >> $out295 ${mkBench{296name="std.base64";297path="${goJsonnetBench}/base64.jsonnet";298skipRustAlternative=skipSlow;299skipCpp="too slow, takes hours, skews results";300skipScala=skipSlow;301}}302 ${mkBench{303name="std.base64Decode";304path="${goJsonnetBench}/base64Decode.jsonnet";305skipRustAlternative=skipSlow;306skipCpp=skipSlow;307skipScala=skipSlow;308}}309 ${mkBench{310name="std.base64DecodeBytes";311path="${goJsonnetBench}/base64DecodeBytes.jsonnet";312skipRustAlternative=skipSlow;313skipCpp=skipSlow;314skipGo=skipSlow;315skipScala=skipSlow;316}}317 ${mkBench{318name="std.base64 (byte array)";319path="${goJsonnetBench}/base64_byte_array.jsonnet";320skipRustAlternative=skipSlow;321skipCpp=skipSlow;322skipGo=skipSlow;323skipScala=skipSlow;324}}325 ${mkBench{326name="std.foldl";327path="${goJsonnetBench}/foldl.jsonnet";328skipScala=skipSlow;329}}330 ${mkBench{331name="std.manifestJsonEx";332path="${goJsonnetBench}/manifestJsonEx.jsonnet";333skipScala=skipSlow;334skipCpp=skipSlow;335}}336 ${mkBench{337name="std.manifestTomlEx";338path="${goJsonnetBench}/manifestTomlEx.jsonnet";339skipCpp=skipSlow;340}}341 ${mkBench{342name="std.parseInt";343path="${goJsonnetBench}/parseInt.jsonnet";344skipScala=skipSlow;345skipCpp=skipSlow;346}}347 ${mkBench{348name="std.reverse";349path="${goJsonnetBench}/reverse.jsonnet";350skipCpp=skipSlow;351skipGo=skipSlow;352}}353 ${mkBench{354name="std.substr";355path="${goJsonnetBench}/substr.jsonnet";356skipScala=skipSlow;357}}358 ${mkBench{359name="Comparsion for array";360path="${goJsonnetBench}/comparison.jsonnet";361skipCpp="too slow, takes hours, skews results";362}}363 ${mkBench{364name="Comparsion for primitives";365path="${goJsonnetBench}/comparison2.jsonnet";366skipRustAlternative=skipSlow;367skipCpp="can't run: uses up to 192GB of RAM";368skipGo=skipSlow;369skipScala=skipSlow;370}}371 '';372}