Jump to content

Speed Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
I've got some data I get from a Card's driver that's in a double array of 4 X 16,000 Points double[5,16000]

Now I'm trying to send this data from the main application to a DLL via a Pipe.

Convert Doubles to String
        private static void ProcessData(int count)
        {
            string SingleLineTestData = "";
            TestResults = "";
            for (int I = 0; I < count ; I++)
            {
                SingleLineTestData = RawTestData[0, I].ToString() + ",";
                SingleLineTestData += RawTestData[1, I].ToString() + ",";
                SingleLineTestData += RawTestData[2, I].ToString() + ",";
                SingleLineTestData += RawTestData[3, I].ToString();
                TestResults += SingleLineTestData + ":";
            }
        }

Send String Via Pipe Out
        private static StreamWriter PipeWriter;
        public static bool PipeWrite(string PipeData)
        {
            bool ValidPipeOut = false;
            if (PipeData!=null)
            try
            {
               PipeWriter.AutoFlush = true;
               PipeWriter.WriteLine(PipeData);
                ValidPipeOut = true;
            }
            catch
            {
                ValidPipeOut = false;
            }
            return ValidPipeOut;
        }

The Problem is I'm getting a large time Hit to covert 64,000 Doubles to a String so I can send them Via the Pipe.

Is there a more efferent way of either
1) Converting Doubles to a String
2) A way to Send a Double Array Via the Pipe without converting to a String.

The Reason I Add the ":" & the "," Is I can then Split the string via ":" for each line, and then each line can be split on the "," for each value.

#2
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Got it. Surprised at the reduction is speed to boot :D
If I've Got my timing right, I went from 36 Seconds for 16,000 X 5 Conversions to 52milliseconds for the same conversion by using StringBuilder
            FinalString = "";
            StringBuilder TempString = new StringBuilder();
            // Convert to String Via String Builder
            ourStopwatch.Reset();
            ourStopwatch.Start();
            for (int I = 0; I < 16000; I++)
            {
                TempString.Append(DummyArray[0, I].ToString()); TempString.Append(",");
                TempString.Append(DummyArray[1, I].ToString()); TempString.Append(",");
                TempString.Append(DummyArray[2, I].ToString()); TempString.Append(",");
                TempString.Append(DummyArray[3, I].ToString()); TempString.Append(",");
                TempString.Append(DummyArray[4, I].ToString()); TempString.Append(":");
            }
            FinalString = TempString.ToString();
            ourStopwatch.Stop();
            Time1.Text = ourStopwatch.ElapsedMilliseconds.ToString();