Created
November 10, 2015 22:50
-
-
Save dmitry-ra/d35b4863b31c5e1b47ac to your computer and use it in GitHub Desktop.
NAudio CircularBuffer test
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.Tasks; | |
using NAudio.Utils; | |
namespace NAudioBugTest | |
{ | |
class Program | |
{ | |
static CircularBuffer _testBuffer; | |
static long _added, _skipped, _count; | |
static volatile bool _running; | |
static void Main(string[] args) | |
{ | |
_running = true; | |
_count = 1000000; | |
_testBuffer = new CircularBuffer(15 * 1024 * 1024); | |
_added = _skipped = 0; | |
var writeTask = Task.Factory.StartNew(WriteTest, TaskCreationOptions.LongRunning); | |
var readTask = Task.Factory.StartNew(ReadTest, TaskCreationOptions.LongRunning); | |
writeTask.Wait(); | |
_running = false; | |
readTask.Wait(); | |
Console.WriteLine("added: {0}, skipped: {1}", _added, _skipped); | |
Console.ReadLine(); | |
} | |
private static void ReadTest() | |
{ | |
int skipCount; | |
while ((skipCount = _testBuffer.Count) > 0 || _running) | |
{ | |
_testBuffer.Advance(skipCount); | |
_skipped += skipCount; | |
} | |
} | |
private static void WriteTest() | |
{ | |
byte[] data = new byte[10]; | |
for (long i = 0; i < _count; i++) | |
{ | |
_added += _testBuffer.Write(data, 0, data.Length); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment