private void handleQueue(AsyncRequestQueue q, int cnt) { Stopwatch w = new Stopwatch(); w.Start(); Dict <int, int> dict = new Dict <int, int>(cnt); for (int i = 0; i < cnt; i++) { dict.Add(i, -1); AsyncElt popped = (AsyncElt)q.PushAndOptionalPop(new AsyncElt(i)); processPopped(dict, popped); } while (true) { AsyncElt popped = (AsyncElt)q.Pop(); if (popped == null) { break; } processPopped(dict, popped); } Assert.AreEqual(cnt, dict.Count); foreach (var kvp in dict) { Assert.AreEqual(2 * kvp.Key, kvp.Value, "value for {0} was {1}", kvp.Key, kvp.Value); } Console.WriteLine("Elapsed: {0}ms for q={1}", w.ElapsedMilliseconds, q); }
private void processPopped(Dict <int, int> dict, AsyncElt popped) { if (popped == null) { return; } Assert.AreEqual(2 * popped.req, popped.resp); int existing; Assert.IsTrue(dict.TryGetValue(popped.req, out existing), "elt {0} is missing", popped.req); Assert.AreEqual(-1, existing, "existing for {0} was {1}", popped.req, existing); dict[popped.req] = popped.resp; }