View benchmark.cs
namespace C_Sharp_Benchmarker | |
{ | |
class Program | |
{ | |
private static int testIterations = 10000000; | |
public static void Main(string[] args) | |
{ | |
var t1 = Test1(); | |
var t2 = Test2(); |
View example.cs
var leave = false; | |
while (someCondition && !leave) | |
{ | |
System.Threading.Thread.Sleep(500); | |
Application.Current.Dispatcher.Invoke(new Action(() => | |
{ | |
if (someOtherCondition) | |
{ |
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 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; |
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 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: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; | |
} |
OlderNewer