DateTime Constructor performance
-
Hi all! I'm working on a .NET data provider, and the DateTime Constructor is killing me. The data is coming from a byte array (which is an ODBC TimeStamp structure) and I'm tearing it apart and stuffing it into a DateTime. In my test application, it takes me 10+ seconds to return 10,000 records from the DB. If I comment out the DateTime constructor line and just return null for the DateTime, it only takes 2 seconds to return the 10,000 records. So far, I've tried every constructor to see if there was any different performance. The only constructor that had any difference was the DateTime(long) (ie, number of ticks since 1/1/1), but how do you calculate how many ticks a given date is?. All of the properties are read-only, so I can't create a temp DateTime and just set my values (or can I?). I'm really kind of at a loss here... Anyone have any ideas? Josh Find a penny, pick it up, and all day long you'll have a back-ache...
-
Hi all! I'm working on a .NET data provider, and the DateTime Constructor is killing me. The data is coming from a byte array (which is an ODBC TimeStamp structure) and I'm tearing it apart and stuffing it into a DateTime. In my test application, it takes me 10+ seconds to return 10,000 records from the DB. If I comment out the DateTime constructor line and just return null for the DateTime, it only takes 2 seconds to return the 10,000 records. So far, I've tried every constructor to see if there was any different performance. The only constructor that had any difference was the DateTime(long) (ie, number of ticks since 1/1/1), but how do you calculate how many ticks a given date is?. All of the properties are read-only, so I can't create a temp DateTime and just set my values (or can I?). I'm really kind of at a loss here... Anyone have any ideas? Josh Find a penny, pick it up, and all day long you'll have a back-ache...
You might consider running the fetch in a thread so that the user is less affected by the delay.
α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides -
You might consider running the fetch in a thread so that the user is less affected by the delay.
α.γεεκ
Fortune passes everywhere.
Duke Leto AtreidesThanks for the suggestion, but it really isn't an option :((. I found that the only constructor that is worth anything (performance-wise) is the DateTime(long ticks), but I was having a hard time converting the date from an ODBC structure to the tick value. I found a work-around by using the FromOADate(double date) static function that had similar speedy performance. I wrote some code to convert the ODBC date to an OLE Automation date, and :-D, I'm back in business! Josh Find a penny, pick it up, and all day long you'll have a back-ache...