The Computer Language
24.11 Benchmarks Game

binary-trees C# aot #6 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 9.0.100
Host Version: 9.0.0
Commit: 9d5a6a9aa4

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


 Wed, 13 Nov 2024 23:59:44 GMT

MAKE:
cp binarytrees.csharpaot-6.csharpaot Program.cs
cp Include/csharpaot/program.csproj .
mkdir obj
cp Include/csharpaot/project.assets.json ./obj
/opt/src/dotnet-sdk-9.0.100/dotnet publish
  Determining projects to restore...
  Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/program.csproj (in 6.36 sec).
/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-6.csharpaot_run] Error 1 (ignored)

13.21s to complete and log all make actions

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

MAKE ERROR