This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace CSharpRecursion | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Counted to {0}.", CountRecursively(10000)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace CSharpAsyncRecursion | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace CSharpAsyncRecursion | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Threading | |
let rec countRecursivelyAsync count = async { | |
if count <= 0 then | |
return count | |
else | |
let! result = countRecursivelyAsync(count - 1) | |
return result + 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto computeSum(char* fileName) { | |
auto fIn = open(fileName, O_RDONLY | O_BINARY, 0644); | |
static constexpr size_t BUFFER_SIZE = 1 << 16; | |
uint8_t buffer[BUFFER_SIZE]; | |
uint8_t const* pBuffer = nullptr; | |
size_t bufferPos = 0; | |
size_t bufferLen = 0; | |
int64_t sum = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long ComputeSum(string fileName, | |
Func<ReadOnlyMemory<byte>, long, int, (long, int)> sumComputer) | |
{ | |
using var fs = new FileStream(fileName, FileMode.Open); | |
using var lease = MemoryPool<byte>.Shared.Rent(MinBufferSize); | |
var buffer = lease.Memory; | |
long sum = 0; | |
int n = 0; | |
while (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<long> ComputeSumAsync(string fileName, | |
Func<ReadOnlyMemory<byte>, long, int, (long, int)> sumComputer, | |
CancellationToken ct = default) | |
{ | |
await using var fs = new FileStream(fileName, FileMode.Open); | |
var pipe = new Pipe(new PipeOptions( | |
minimumSegmentSize: MinBufferSize, | |
useSynchronizationContext: false)); | |
async Task ProduceAsync() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static unsafe (long, int) ComputeSumSimd( | |
ReadOnlyMemory<byte> buffer, long sum, int n) | |
{ | |
var span = buffer.Span; | |
fixed (byte* pStart = span) { | |
return ComputeSumSimd(new IntPtr(pStart), span.Length, sum, n); | |
} | |
} | |
private static unsafe (long, int) ComputeSumSimd( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long ComputeSumMMF(string fileName, | |
Func<IntPtr, long, long, int, (long, int)> sumComputer) | |
{ | |
using var f = MemoryMappedFile.CreateFromFile(fileName, FileMode.Open); | |
using var fAccessor = f.CreateViewAccessor(); | |
var fHandle = fAccessor.SafeMemoryMappedViewHandle; | |
var (sum, _) = sumComputer(fHandle.DangerousGetHandle(), (long) fHandle.ByteLength, 0, 0); | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rem Copy this text to BeatSaberLauncher.bat & use it to start Beat Saber | |
@start "Beat Saber Launcher" powershell.exe -File BeatSaberLauncher.ps1 |
OlderNewer