Thread: Guid default equality comparer

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    Guid default equality comparer

    I have a dictionary which maps a Guid to Orders, it contains like 350000 orders

    Code:
    Dictionary<Guid, Order> htPreOrders = new Dictionary<Guid, PreOrder>(350000);
    Im trying to optimize it by replacing the IEqualityComparer by a custom one.

    Code:
            class Comp : IEqualityComparer<Guid>
            {
                public bool Equals(Guid x, Guid y)
                {
                    return x == y;
                }
                public int GetHashCode(Guid obj)
                {
                    return obj.GetHashCode();
                }
    
    Dictionary<Guid, Order> htPreOrders = new Dictionary<Guid, PreOrder>(350000, new Comp());
    would this be faster, or is that the same as the default equality comparer of Guid?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I don't see any reason why it would be faster. You need to check if this part of your program actually needs optimization, because you seem to be guessing a lot.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Im learning c# and making software at the same time. So ye Im guessing a lot on how to optimize things but this part needs optimization. Its a database which takes half an hour to retrieve which uses guids for primary keys. But anyway this was not an improvement.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by KIBO View Post
    Im learning c# and making software at the same time. So ye Im guessing a lot on how to optimize things but this part needs optimization. Its a database which takes half an hour to retrieve which uses guids for primary keys. But anyway this was not an improvement.
    I would doubt it's taking 30 minutes to actually do the comparison(s) needed in a lookup - with the number of objects in your "database" your hash collisions should be relatively small, so most of the lookups will be O(1).
    I'd rethink your paradigm - local variables are not intended to replace an actual database; use a real database if you need one.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. default comparer
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-13-2008, 03:46 AM
  2. GUID Generation Question
    By mercury529 in forum Windows Programming
    Replies: 9
    Last Post: 01-15-2007, 04:05 PM
  3. Guid questions
    By kryptkat in forum Tech Board
    Replies: 2
    Last Post: 08-25-2006, 03:07 PM
  4. How is GUID generated?
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 03-12-2004, 10:38 PM
  5. plz guid me
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-19-2002, 06:08 PM