static void RunConcurrentHashSet() { var threads = new List <Task>(); var sw = new Stopwatch(); var ch = new ConcurrentHashSet <DataTable>(); sw.Start(); for (int runCount = 0; runCount < TestRunCount; runCount++) { threads.Add(Task.Factory.StartNew(() => ProcessConcurrentHashSet(ch, TestRunCollectionCount))); } Task.WaitAll(threads.ToArray()); sw.Stop(); //Test XML //var xml = XmlHelper.Serialize(ch); //var xmlResult = XmlHelper.Deserialize<ConcurrentHashSet<DataTable>>(xml); //var json = ch.ToJson(); //var jsonResult = json.FromJson<ConcurrentHashSet<DataTable>>(); var count = ch.Count(); double avg = sw.ElapsedMilliseconds / count; Console.WriteLine("ConcurrentHasSet test took {0} milliseconds, Count={1}-{2}.", sw.ElapsedMilliseconds, count, avg); Console.WriteLine(); }
/// <summary> /// 获取缓存数量 /// </summary> /// <param name="prefix">缓存键前缀</param> /// <returns></returns> public int GetCount(string prefix = "") { return(string.IsNullOrWhiteSpace(prefix) ? _cacheKeys.Count : _cacheKeys.Count(x => x.StartsWith(BuildCacheKey(Name, prefix.Trim()), StringComparison.OrdinalIgnoreCase))); }