Click here to Skip to main content
15,920,633 members
Home / Discussions / C#
   

C#

 
AnswerRe: saving file into sql database Pin
joon vh.19-Mar-07 22:48
joon vh.19-Mar-07 22:48 
QuestionMSBuild Question Pin
Member 390685019-Mar-07 20:53
Member 390685019-Mar-07 20:53 
QuestionFastest way to write a text file Pin
blackjack215019-Mar-07 20:51
blackjack215019-Mar-07 20:51 
AnswerRe: Fastest way to write a text file Pin
Russell Jones19-Mar-07 22:08
Russell Jones19-Mar-07 22:08 
GeneralRe: Fastest way to write a text file Pin
blackjack215019-Mar-07 22:33
blackjack215019-Mar-07 22:33 
GeneralRe: Fastest way to write a text file Pin
m@u19-Mar-07 23:18
m@u19-Mar-07 23:18 
GeneralRe: Fastest way to write a text file Pin
PIEBALDconsult23-Feb-10 10:46
mvePIEBALDconsult23-Feb-10 10:46 
AnswerRe: Fastest way to write a text file Pin
joon vh.19-Mar-07 22:22
joon vh.19-Mar-07 22:22 
I mocked up a quick perf. test. You can run it yourself to see the results (in VS 2005).

Just make an empty console app. and past this code:

    class Program<br />
    {<br />
        static string printme =<br />
            "Fastest way to write a text file Fastest way to write a text file Fastest way to write a text file";<br />
<br />
        static void Main(string[] args)<br />
        {<br />
            // start the first stopwatch <br />
<br />
            Stopwatch sw = new Stopwatch();<br />
            sw.Start();<br />
<br />
            // run the first test (stream)<br />
<br />
            test1();<br />
<br />
            // stop stopwatch and print<br />
<br />
            sw.Stop();<br />
            Console.WriteLine(sw.Elapsed);<br />
<br />
            // reset <br />
<br />
            sw.Reset();<br />
<br />
            // start second stopwatch<br />
            <br />
            sw.Start();<br />
<br />
            // run second test<br />
<br />
            test2();<br />
<br />
            // stop stopwatch and print<br />
<br />
            sw.Stop();<br />
            Console.WriteLine(sw.Elapsed);<br />
<br />
            // hold for laughs<br />
<br />
            Console.Read();<br />
        }<br />
<br />
<br />
        /// <summary><br />
        /// Method that writes 5000 lines of text with a streamwriter<br />
        /// </summary><br />
        static void test1()<br />
        {<br />
            TextWriter tw = new StreamWriter("test1.txt");<br />
            for (int i = 0; i < 50000; i++)<br />
            {<br />
                tw.WriteLine(i + " " + printme);<br />
            }<br />
            tw.Close();<br />
        }<br />
<br />
        /// <summary><br />
        /// Method that writes 5000 lines of text with the static methods from the File class<br />
        /// </summary><br />
        static void test2()<br />
        {<br />
            for (int i = 0; i < 50000; i++)<br />
            {<br />
                 File.AppendAllText("test2.txt",i + " " + printme + "\n\r");<br />
            }<br />
        }<br />
    }


I hope my logic is right, and if it is, you will hopefulyl see the same result as me. Streamwriter completes in a few seconds, and File.AppendAllText... takes forever.
There is also AppendText, but that returns a streamwriter and gives you the same result as test1.

Hope I helped.




public object BufferOverFlow<br />
        {<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}

AnswerRe: Fastest way to write a text file Pin
Guffa19-Mar-07 22:30
Guffa19-Mar-07 22:30 
GeneralRe: Fastest way to write a text file Pin
joon vh.19-Mar-07 23:49
joon vh.19-Mar-07 23:49 
GeneralRe: Fastest way to write a text file Pin
Guffa20-Mar-07 2:10
Guffa20-Mar-07 2:10 
GeneralRe: Fastest way to write a text file Pin
joon vh.20-Mar-07 2:50
joon vh.20-Mar-07 2:50 
QuestionPlacing RadioButton in Nodes of TreeView Pin
SakthiSurya19-Mar-07 20:42
SakthiSurya19-Mar-07 20:42 
AnswerRe: Placing RadioButton in Nodes of TreeView Pin
stancrm19-Mar-07 21:03
stancrm19-Mar-07 21:03 
Questiondatagrid with checkbox for pocket pc 2003 Pin
mohdmeraj19-Mar-07 20:17
mohdmeraj19-Mar-07 20:17 
Questionhow to get create query of msaccess table through c# Pin
joerozario19-Mar-07 19:18
joerozario19-Mar-07 19:18 
AnswerRe: how to get create query of msaccess table through c# Pin
sujithkumarsl19-Mar-07 19:59
sujithkumarsl19-Mar-07 19:59 
GeneralRe: how to get create query of msaccess table through c# Pin
joerozario19-Mar-07 20:21
joerozario19-Mar-07 20:21 
GeneralRe: how to get create query of msaccess table through c# Pin
sujithkumarsl19-Mar-07 20:34
sujithkumarsl19-Mar-07 20:34 
GeneralRe: I want to get the create query of existing table Pin
joerozario19-Mar-07 21:10
joerozario19-Mar-07 21:10 
GeneralRe: I want to get the create query of existing table Pin
joerozario19-Mar-07 21:26
joerozario19-Mar-07 21:26 
GeneralRe: I want to get the create query of existing table Pin
Russell Jones19-Mar-07 21:56
Russell Jones19-Mar-07 21:56 
GeneralRe: I want to get the create query of existing table Pin
joerozario19-Mar-07 22:42
joerozario19-Mar-07 22:42 
GeneralRe: I want to get the create query of existing table Pin
Russell Jones20-Mar-07 3:36
Russell Jones20-Mar-07 3:36 
GeneralRe: how to get create query of msaccess table through c# Pin
V.19-Mar-07 22:57
professionalV.19-Mar-07 22:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.