The Computer Language
24.09 Benchmarks Game

binary-trees C# aot #8 program

source code

// The Computer Language Benchmarks Game
// https://benchmarksgame-team.pages.debian.net/benchmarksgame/
//
// based on
// - Tristan Dupont Java #7
// - Anthony Lloyd C#
// - Isaac Guoy C# #7
// - Steve (hez2010) https://github.com/dotnet/runtime/issues/101006#issue-2241502984
// contributed by Arseniy Zlobintsev

not accepted kind-of interesting

using System;
using System.Linq;
using System.Threading.Tasks;

const int minDepth = 4;

var workers = Environment.ProcessorCount;
var maxDepth = args.Length is 0 ? 10
    : Math.Max(minDepth + 2, int.Parse(args[0]));

Console.WriteLine(
    $"stretch tree of depth {maxDepth + 1}\t check: {new TreeNode(maxDepth + 1).Check()}");

var longLivedTree = new TreeNode(maxDepth);

var results = new string[((maxDepth - minDepth) / 2) + 1];
for (var i = 0; i < results.Length; i++) {
    var depth = (i * 2) + minDepth;
    var n = (1 << (maxDepth - depth + minDepth)) / workers;
    var checks = new int[workers];
    Parallel.For(0, workers, w => {
        var check = 0;
        for (var i = n; i > 0; i--)
            check += new TreeNode(depth).Check();
        checks[w] = check;
    });
    results[i] = $"{n * workers}\t trees of depth {depth}\t check: {checks.Sum()}";
}

foreach (var r in results)
    Console.WriteLine(r);

Console.WriteLine(
    $"long lived tree of depth {maxDepth}\t check: {longLivedTree.Check()}");

readonly struct TreeNode(int depth) {
    record Next(TreeNode Left, TreeNode Right);
    readonly Next? next = depth > 0
        ? new(new(depth - 1), new(depth - 1))
        : null;

    public int Check() {
        return next is null ? 1 : 1 + next.Left.Check() + next.Right.Check();
    }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
.NET SDK 8.0.301
Host Version: 8.0.6
Commit: 3b8b000a0e

<OutputType>Exe
<TargetFramework>net8.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>true
<OptimizationPreference>Speed
<IlcInstructionSet>native


 Mon, 19 Aug 2024 21:06:26 GMT

MAKE:
cp binarytrees.csharpaot-8.csharpaot Program.cs
cp Include/csharpaot/program.csproj .
mkdir obj
cp Include/csharpaot/project.assets.json ./obj
~/dotnet/dotnet publish
  Determining projects to restore...
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj (in 6.19 sec).
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/Program.cs(11,14): error CS1003: Syntax error, ',' expected [/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj]
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/Program.cs(11,33): error CS1002: ; expected [/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj]
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/Program.cs(13,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations [/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj]
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/Program.cs(14,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations [/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj]
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/Program.cs(15,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations [/home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj]
make: [/home/dunham/all-benchmarksgame/2000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:185: binarytrees.csharpaot-8.csharpaot_run] Error 1 (ignored)

14.92s to complete and log all make actions

COMMAND LINE:
 ./bin/Release/net8.0/linux-x64/native/program 7

MAKE ERROR