Skip to content

Instantly share code, notes, and snippets.

View alexyakunin's full-sized avatar
👨‍💻
Working on something new!

Alex Yakunin alexyakunin

👨‍💻
Working on something new!
View GitHub Profile
@alexyakunin
alexyakunin / Fusion-Performance-Test.cmd
Last active November 17, 2021 05:42
Run Fusion performance test
dotnet build -c Release
Run-PerformanceTest.cmd net6.0
Run-PerformanceTest.cmd net5.0
Run-PerformanceTest.cmd netcoreapp3.1
@alexyakunin
alexyakunin / EnablePGO.cmd
Created November 17, 2021 05:25
.NET 6 w/ PGO enabled
set DOTNET_ReadyToRun=0
set DOTNET_TieredPGO=1
set DOTNET_TC_QuickJitForLoops=1
@alexyakunin
alexyakunin / coronavirus.py
Last active March 15, 2020 08:59
An attempt to estimate COVID-19 transmission rate
def clamp(x, x_min, x_max):
return max(x_min, min(x_max, x))
def safe_segment(a, start=0, end=None):
if end is None:
end = len(a)
start = clamp(start, 0, len(a))
end = clamp(end, start, len(a))
return a[start:end]
@alexyakunin
alexyakunin / BeatSaberLauncher.ps1
Last active December 28, 2019 05:59
Beat Saber Launcher - PowerShell script
# Copy the text below to BeatSaberLauncher.ps1
# You may need to edit the path below
# The default Beat Saber location for Steam version:
Set-Location -Path "C:\Program Files\Steam\steamapps\common\Beat Saber"
# The default Beat Saber location for Oculus version:
# Set-Location -Path "C:\Program Files\Oculus\Software\Software\hyperbolic-magnetism-beat-saber"
Start-Process -FilePath "Beat Saber.exe"
Write-Output "Beat Saber started."
@alexyakunin
alexyakunin / BeatSaberLauncher.bat
Last active December 28, 2019 00:26
Beat Saber Launcher - .bat script
@rem Copy this text to BeatSaberLauncher.bat & use it to start Beat Saber
@start "Beat Saber Launcher" powershell.exe -File BeatSaberLauncher.ps1
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;
}
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(
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() {
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) {
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;