Double the speed of FbDataReader.GetOrdinal()
---------------------------------------------

                 Key: DNET-214
                 URL: http://tracker.firebirdsql.org/browse/DNET-214
             Project: .NET Data provider
          Issue Type: Improvement
          Components: ADO.NET Provider
         Environment: N/A
            Reporter: Gareth Goslett
            Assignee: Jiri Cincura
            Priority: Trivial


By creating a hashtable on first access to the GetOrdinal method and populating 
it with the fields and indexes we only need to get the hash code of the 
requested field name for future lookups.

I did some tests on a table with 10 fields and 1000 records. I read all records 
5 times so there were 5 * 1000 * 10 lookups.

CURRENT GetOrdinal
Total ordinal reads: 5000
  Result 13
  Result 11
  Result 11
  Result 10
  Result 10
Average time 0.011
Total named reads  : 5000
  Result 33
  Result 33
  Result 36
  Result 32
Average time 0.0268

NEW GetOrdinal
Total ordinal reads: 5000
  Result 13
  Result 9
  Result 10
  Result 10
  Result 9
Average time 0.0102
Total named reads  : 5000
  Result 13
  Result 16
  Result 14
  Result 14
Average time 0.0114

Here is the new method:

Hashtable names;
public override int GetOrdinal(string name)
{
    this.CheckState();

    if (names == null)
    {
        names = new Hashtable();
      for (int i = 0; i < this.fields.Count; i++)
      {
        names.Add(this.fields[i].Alias.ToLowerInvariant().GetHashCode(), i);
      }
    }

    int hash = name.ToLowerInvariant().GetHashCode();

    if (names.ContainsKey(hash) == true)
    {
        return (Int32)names[hash];
    }

    throw new IndexOutOfRangeException("Could not find specified column in 
results.");
}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to