Skip to content

C# Simple Program - fix STDOUT assumption and match Go # 2 submission

CONTRIBUTE SOURCE CODE

Provide a helpful Title

C# Simple Program - fix STDOUT assumption, match Go #2 submission and base C# console template

Attach your source code file

Simple.csSimple.csproj

Provide an example build command-line

dotnet publish -o .
./Simple 16000

Discussion

This change updates existing C# submission for simple program.
The .csproj file is provided as-is from the output of dotnet new console --aot. Notably, it uses <ImplicitUsings>true</ImplicitUsings> which is a default since .NET 6. Previous submissions did not seem to use it but it makes sense to add it. If you feel like the use of AOT target is inappropriate, feel free to remove or comment out the property. I noticed that the build is a bit involved for it and could be a single one-liner. Please let me know if you would like to simplify it, retaining JIT mode.

In addition, floating-point code is changed to match 1:1 number 2 submissions of C and Go. I'm not sure if this should be named a C# 2 submission or not and leave this to your discretion.

Most importantly, current C# submission has incorrect assumption that Console.OpenStandardOutput() is buffered. Like Rust and Go, and unlike Java - it isn't. Go submissions use bufio Writer, so I think it's appropriate to match it.

During investigation, additional minor issues regarding FP optimizations (suboptimal CSE heuristics and constant folding) were found and corresponding issues will be submitted at dotnet/runtime. They do not measurably affect this benchmark case however.

Thanks!