public void Init() { queue = new RelaxedLotanShavitSkipList_v2 <int>(); threadCount = Environment.ProcessorCount + 2; n = 10; prefill = true; }
public static BlockingCollection <T> ToBlockingCollection <T, TP>(this IConcurrentPriorityQueue <T, TP> queue) where T : IHavePriority <TP> where TP : IEquatable <TP>, IComparable <TP> { if (queue.Capacity > 0) { return(new BlockingCollection <T>(queue, queue.Capacity)); } return(new BlockingCollection <T>(queue)); }
public static BlockingCollection <T> ToBlockingCollection <T, TP>(this IConcurrentPriorityQueue <T, TP> queue, int capacity) where T : IHavePriority <TP> where TP : IEquatable <TP>, IComparable <TP> { if (capacity < 0) { throw new ArgumentOutOfRangeException("capacity"); } return(new BlockingCollection <T>(queue, capacity)); }
public PriorityQueueIEnumerabeUnitTests() { _targetQueue = new ConcurrentPriorityByIntegerQueue <IHavePriority <int> >(); }
public PriorityQueueIProducerConsumerUnitTests() { _targetQueue = new ConcurrentPriorityByIntegerQueue <IHavePriority <int> >(); }
public GenericPriorityQueueIProducerConsumerUnitTests() { _targetQueue = new ConcurrentPriorityQueue <IHavePriority <TimeToProcess>, TimeToProcess>(); }
/// <summary> /// Main benchmarking method /// </summary> /// <param name="config"></param> /// <param name="type"></param> void BenchMark(BenchmarkConfig config, Type type) { var SecondsPerTestTimer = new Stopwatch(); //Run the benchmark for all the number of threads specified foreach (int threadsToRun in config.Threads) { SecondsPerTestTimer.Reset(); var tempThroughPut = new ArrayList <Int64>(); Int64 throughput = 0; int runs = 0; //Inner loop that runs until standard deviation is below some threshold or it has done too many runs and throws an exception while ((SecondsPerTestTimer.ElapsedMilliseconds / 1000.0) < ((config.SecondsPerTest * 1.0) / config.Threads[config.Threads.Length - 1]) || runs <= ((config.WarmupRuns) + config.Threads[0])) { if (type.Equals(typeof(SprayList <int>))) { dictionary = (IConcurrentPriorityQueue <int>)Activator.CreateInstance(type, threadsToRun); } else { dictionary = (IConcurrentPriorityQueue <int>)Activator.CreateInstance(type); } //dictionary = new GlobalLockDEPQ<int>(); // Create the correct dictionary for this run // Get tree to correct size before we start, if applicable. if (config.Prefill) { /* Each trial should start with trees that are prefilled to their expected size in the steady state, * so that you are measuring steady state performance, and not inconsistent performance as the size * of the tree is changing. If your experiment consists of random operations in the proportions * i% insertions, d% deletions, and s% searches on keys drawn uniformly randomly from a key range of * size r, then the expected size of the tree in the steady state will be ri/(i+d) */ int r = (config.EndRangeRandom - config.StartRangeRandom) * 4; // double the range int steadyStateSize = config.CurrentNumberOfElements / 2; if (config.CurrentPercentageInsert > 0 && config.CurrentPercentageDeleteMin > 0 && config.CurrentPercentageDeleteMax > 0) { steadyStateSize = (r * config.CurrentPercentageInsert) / (config.CurrentPercentageInsert + config.CurrentPercentageDeleteMin + config.CurrentPercentageDeleteMax); } if (steadyStateSize > r) { throw new Exception("Range of numbers is too small to reach steady state"); } Queue <int> threadQueue = generateRandomQueue(steadyStateSize, config.StartRangeRandom, config.EndRangeRandom); //double the size while (threadQueue.Count > 0) { int element = threadQueue.Dequeue(); dictionary.Add(element); } } // Create the start and end barrier barrier = new Barrier(threadsToRun + 1); // Submit the work for (int threads = 1; threads <= threadsToRun; threads++) { int start = config.StartRangeRandom; int end = config.EndRangeRandom; Queue <int> threadQueue = generateRandomQueue(config.CurrentNumberOfElements, start, end); Thread thread = new Thread(Work); thread.Start(threadQueue); } barrier.SignalAndWait();// Wait for all tasks / threads to be ready to begin work var t = new Stopwatch(); // Start the timers t.Start(); SecondsPerTestTimer.Start(); barrier.SignalAndWait(); // Wait for all tasks / threads to be finished with their work. Unlike Java, no need to reset the barrier in C# double time = t.ElapsedTicks; // Get elapsed time config.ExecutionTime = t.ElapsedMilliseconds; SecondsPerTestTimer.Stop(); if (runs > config.WarmupRuns) // Only add results after the warmup runs { Int64 toAdd = (Int64)(((config.CurrentNumberOfElements * threadsToRun) / time) * 1000.0 * 10000.0); tempThroughPut.Add(toAdd); } runs++;// Increment number of runs } throughput = (Int64)tempThroughPut.Average(); if (throughput > maxThroughput) { maxThroughput = throughput; } //add a line with threads and execution time and a line with threads and throughput //datafile.Log(threadsToRun + " " + config.ExecutionTime); datafile.Log(threadsToRun + " " + throughput); } }
public void Dispose() { queue = null; }
public void Init() { queue = new RelaxedLotanShavitSkipList_v2 <int>(); }