public void TestMemory() { int times = 5000000; IDuplicateRemover duplicateRemover = new BloomFilterDuplicateRemover(times, 0.005); long used = GetProcessUsedMemory(); long time = DateTime.UtcNow.CurrentTimeMillis(); for (int i = 0; i < times; i++) { duplicateRemover.IsDuplicate(new Request(i.ToString(), null), null); } Console.WriteLine("Time used by bloomfilter:" + (DateTime.UtcNow.CurrentTimeMillis() - time)); Console.WriteLine("Memory used by bloomfilter:" + (GetProcessUsedMemory() - used)); duplicateRemover = new HashSetDuplicateRemover(); GC.Collect(); used = GetProcessUsedMemory(); time = DateTime.UtcNow.CurrentTimeMillis(); for (int i = 0; i < times; i++) { duplicateRemover.IsDuplicate(new Request(i.ToString(), null), null); } Console.WriteLine("Time used by hashset:" + (DateTime.UtcNow.CurrentTimeMillis() - time)); Console.WriteLine("Memory used by hashset:" + (GetProcessUsedMemory() - used)); }
public void HashSetDuplicateSynchronized() { HashSetDuplicateRemover scheduler = new HashSetDuplicateRemover(); bool isDuplicate = scheduler.IsDuplicate(new Request("http://www.a.com", 1, null)); Assert.IsFalse(isDuplicate); Parallel.For(0, 1000, new ParallelOptions() { MaxDegreeOfParallelism = 30 }, i => { isDuplicate = scheduler.IsDuplicate(new Request("http://www.a.com", 1, null)); Assert.IsTrue(isDuplicate); }); }
public void HashSetDuplicate() { HashSetDuplicateRemover scheduler = new HashSetDuplicateRemover(); bool isDuplicate = scheduler.IsDuplicate(new Request("http://www.a.com", 1, null), null); Assert.IsFalse(isDuplicate); isDuplicate = scheduler.IsDuplicate(new Request("http://www.a.com", 1, null), null); Assert.IsTrue(isDuplicate); isDuplicate = scheduler.IsDuplicate(new Request("http://www.b.com", 1, null), null); Assert.IsFalse(isDuplicate); isDuplicate = scheduler.IsDuplicate(new Request("http://www.b.com", 1, null), null); Assert.IsTrue(isDuplicate); }