Skip to content

Instantly share code, notes, and snippets.

Avatar
👋
I'll get round to it, eventually.

Sam ArcticEcho

👋
I'll get round to it, eventually.
View GitHub Profile
@ArcticEcho
ArcticEcho / Benchmark
Last active Aug 29, 2015
Run in release config, without optimizations, without debugger & ignore results from first build. (And obviously don't have anything running in the background).
View Benchmark
using System;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
// WARNING: For the code below to exacute properly (without getting a SOE) this program must be
// a full-trust app; see, project properties > security > enable "ClickOnce security setting"
View PFM's Method
// PFM's method.
public static unsafe void TestMethod1()
{
float* samples = stackalloc float[12500];
for (var i = 0; i < 100; i++)
{
for (var ii = 0; ii < 12500; ii++)
{
View Mark's Method
// Mark's method.
public unsafe static void TestMethod2()
{
var ptr = Marshal.AllocHGlobal(50000000);
try
{
float* x = (float*)ptr;
@ArcticEcho
ArcticEcho / Stack vs Heap Benchmark
Last active Aug 29, 2015
Updated M1 vs updated M2.
View Stack vs Heap Benchmark
// M1 is 108% faster than M2.
public static unsafe void TestMethod1()
{
float* samples = stackalloc float[12500];
for (var i = 0; i < 4000; i++)
{
for (var ii = 0; ii < 12500; ii++)
{
View gist:185ee36167d89bcdc55b
// Read32BitSamples is called first.
private float[] Read32BitSamples(FileStream stream, int sampleStartIndex, int sampleEndIndex)
{
var bytesLength = 0;
var allocation = ReadBytes(stream, sampleStartIndex, sampleEndIndex, out bytesLength);
var bytes = (byte*)allocation.Allocation;
var samples = new float[bytesLength / 4];
View gist:c0be89467b86fafea4eb
// Copyright (C) 2014 S.Kamber.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
View gist:499775e964473babc318
// Copyright (C) 2014 S.Kamber.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
View gist:58061f74b0a1d296f99c
vector<WavFileRead> VSSEnvironment::GetChannels(string directory)
{
vector<WavFileRead> files;
if (DirectoryTools::FileExists(directory + ChannelsFunctions::GetFriendlyName(FrontLeft) + ".wav"))
{
files.push_back(WavFileRead(directory + ChannelsFunctions::GetFriendlyName(FrontLeft) + ".wav"));
}
if (DirectoryTools::FileExists(directory + ChannelsFunctions::GetFriendlyName(FrontRight) + ".wav"))
View gist:d28196d8e610b84399fa
private static IEnumerable<WavFileRead> GetChannels(string directory)
{
var files = Enum.GetValues(typeof(Channels)).Cast<Channels>().Where(channel => channel != Channels.Custom && channel != Channels.Mono).Select(channel => Path.Combine(directory, channel.GetFriendlyName() + ".wav")).Where(File.Exists).Select(path => new WavFileRead(path)).ToList();
files.AddRange(Directory.EnumerateFiles(directory).Where(fileName => fileName.Contains(Channels.Mono.GetFriendlyName()) || fileName.Contains(Channels.Custom.GetFriendlyName())).Select(file => new WavFileRead(file)));
return files;
}
View gist:4ed88219d6a39665697e
<A class=\"signature user-227577\" href=\"/users/227577/sam\">\r\n<DIV style=\"DISPLAY: none\" class=tiny-signature
jQuery17106276336429219909=\"318\">\r\n<DIV class=\"avatar avatar-16\"><IMG title=Sam alt=Sam src=\"http://i.stack.imgur.com/Y22En.png?s=128&amp;g=1&amp;g&amp;s=16\"
width=16 height=16></DIV>\r\n<DIV class=\"username owner\">Sam</DIV></DIV>\r\n<DIV style=\"DISPLAY: block\" class=\"avatar avatar-32 clear-both\"
jQuery17106276336429219909=\"57\"><IMG title=Sam alt=Sam src=\"http://i.stack.imgur.com/Y22En.png?s=128&amp;g=1&amp;g&amp;s=32\" width=32 height=32>\r
\n<DIV></DIV></DIV>\r\n<DIV style=\"DISPLAY: block\" class=\"username owner\" jQuery17106276336429219909=\"56\">Sam</DIV>\r\n<DIV class=flair title=125
You can’t perform that action at this time.