Carpe diem!

Make your lives extraordinary

c# : Stupid string Concat

maksutnya supaya lebih mudah diprogramnya, namun apa daya performansinya jauh mengecewakan. itulah yang terjadi saat saya akan menyimpan sebuah array of double dengan menggunakan c#. simple problem :

int nx;
int ny;
double[,] data = new double[nx,ny];
 
saya ingin dump data tersebut menjadi sebuah string lalu mengcompress-nya.

my first simple answer is :

—————————————————————————–
            string result = “”;
            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
//separate row data with space
                    result += data[i, j].ToString() + ” “;
                }
//separate column data with space
                result += “-“;
            }
           result = compress(result);
——————————————————————————–
DEBUG –> RUN …
1 menit berlalu …..
5 menit berlalu …
10 menit berlalu ….
break the RUN…
watch i = 651  dan j = 126
usut punya usut  nx = 931 dan ny=165 …. wahh h…. masih 2/3 jalan nih …
 
langsung ganti algoritma baru :
——————————————————————————–
         public void dumpdatatofile(string filename)
        {
            StreamWriter sr = File.CreateText(filename);

            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    sr.WriteLine(data[i,j].ToString(“E”));
                }
            }

            sr.Close();
        }
        public string loadFileToString(string filename)
        {
            StreamReader sr = File.OpenText(filename);
            string result = sr.ReadToEnd();
            sr.Close();
            return result;

        }

        public void main()
        {
            string filename = “C:\\waveshot.” + Guid.NewGuid().ToString(“N”) + “.tmp”;
            dumpdatatofile(filename);
            cVelocities = Utils.Compress(loadFileToString(filename));
//            File.Delete(filename);
        }

——————————————————————————–
DEBUG –> RUN …
1 second later …. done !!!

wow … dashyattt ….
string concate c# sucksss …..

 

October 30, 2009 - Posted by | Biz to work, Blogroll, code Warior, HPC, Ngoprek, santai, techno | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: