Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DateTime Constructor performance

DateTime Constructor performance

Scheduled Pinned Locked Moved C#
csharpdatabasedata-structuresperformancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josh Martin
    wrote on last edited by
    #1

    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...

    J 1 Reply Last reply
    0
    • J Josh Martin

      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...

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • J Jim Stewart

        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

        J Offline
        J Offline
        Josh Martin
        wrote on last edited by
        #3

        Thanks 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...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups