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. Fast way to convert string array to double array...

Fast way to convert string array to double array...

Scheduled Pinned Locked Moved C#
questioncomdata-structuresperformancehelp
5 Posts 4 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.
  • R Offline
    R Offline
    RYU
    wrote on last edited by
    #1

    Hi, What is the fastest way to convert string array to double array? Currently, I am doing this:

    double[] arrDouble = new double[arrString.Length];
    for(int i=0; i<arrString.Length; i++)
    {
       arrDouble[i] = double.Parse(arrString[i]);
    }
    

    Unfortunately, this is quite slow for big array (about 3 millions). I am looking for a way to improve it. There is a link talking about converting object to double. http://blogs.msdn.com/bclteam/archive/2005/02/11/371436.aspx[^]. You will see that double.Parse is really slow because the object need to be converted to string before pass it to double.Parse. However, it is not the case here. My array is already a string array. I did test using Convert.ToDouble and it doesn't improve the speed. Any idea? Thanks for any help. Cheers :)

    L 1 Reply Last reply
    0
    • R RYU

      Hi, What is the fastest way to convert string array to double array? Currently, I am doing this:

      double[] arrDouble = new double[arrString.Length];
      for(int i=0; i<arrString.Length; i++)
      {
         arrDouble[i] = double.Parse(arrString[i]);
      }
      

      Unfortunately, this is quite slow for big array (about 3 millions). I am looking for a way to improve it. There is a link talking about converting object to double. http://blogs.msdn.com/bclteam/archive/2005/02/11/371436.aspx[^]. You will see that double.Parse is really slow because the object need to be converted to string before pass it to double.Parse. However, it is not the case here. My array is already a string array. I did test using Convert.ToDouble and it doesn't improve the speed. Any idea? Thanks for any help. Cheers :)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This will always be a O(n) operation, you can't get it any faster than this. Are you sure you need 3 million items at the same time? regards

      R 1 Reply Last reply
      0
      • L Lost User

        This will always be a O(n) operation, you can't get it any faster than this. Are you sure you need 3 million items at the same time? regards

        R Offline
        R Offline
        RYU
        wrote on last edited by
        #3

        Yeah, unfortunately :( Thanks though for your help. At least I know there is nothing I can do about it. Cheers :)

        B 1 Reply Last reply
        0
        • R RYU

          Yeah, unfortunately :( Thanks though for your help. At least I know there is nothing I can do about it. Cheers :)

          B Offline
          B Offline
          blackjack2150
          wrote on last edited by
          #4

          Just for curiosity. How long does it take to convert those 3 million items?

          A 1 Reply Last reply
          0
          • B blackjack2150

            Just for curiosity. How long does it take to convert those 3 million items?

            A Offline
            A Offline
            Andrew Carmichael
            wrote on last edited by
            #5

            12 years later and we still haven't heard back. I can see why they wanted to speed this up.

            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