11

I am currently testing the performance of different methods for logging text data into a file. It seems that when I open/write/close a large amount of times, the extension used affects the performance. (.txt and .log are ~7 times faster)

Code used:

private static void TestWriteSpeed(FileInfo file)
{
    Stopwatch watch = new Stopwatch();
    watch.Start();
    for (int i = 0; i < 5000; i++)
    {
        using (StreamWriter writer = file.AppendText())
        {
            writer.Write("This is a test");
        }
    }
    Console.WriteLine(file.Name + ": " + watch.Elapsed);
}

static void Main(string[] args)
{
    TestWriteSpeed(new FileInfo("abc.txt"));
    TestWriteSpeed(new FileInfo("abc.txt.01564611564"));
    TestWriteSpeed(new FileInfo("abc.01564611564.txt"));
    TestWriteSpeed(new FileInfo("abc.xml"));
    TestWriteSpeed(new FileInfo("abc.xml.01564611564"));
    TestWriteSpeed(new FileInfo("abc.config"));
    TestWriteSpeed(new FileInfo("abc.config.01564611564"));
    TestWriteSpeed(new FileInfo("abc.exe"));
    TestWriteSpeed(new FileInfo("abc.exe.01564611564"));
    TestWriteSpeed(new FileInfo("abc.log"));
    TestWriteSpeed(new FileInfo("abc.log.01564611564"));
    Console.ReadLine();
}

Results:

abc.txt                  00:00:08.3826847  <---
abc.txt.01564611564      00:00:59.7401633
abc.01564611564.txt      00:00:08.0069698  <---
abc.xml                  00:00:58.2031820
abc.xml.01564611564      00:00:59.3956204
abc.config               00:00:58.4861308
abc.config.01564611564   00:01:01.2474287
abc.exe:                 00:01:00.0924401
abc.exe.01564611564      00:01:00.7371805
abc.log                  00:00:08.0009934  <---
abc.log.01564611564      00:00:59.8029448

Why is this happening?

4
  • 14
    Antivirus was turned off i hope? Jul 9, 2010 at 15:02
  • 2
    @orsol who on earth would run AV instead of just RANU?
    – user1228
    Jul 9, 2010 at 15:06
  • 1
    @Will: Hey, guess what... those updates Microsoft pushes every month? Some of those fix OS holes that are exploitable even if the user currently using the machine isn't an Administrator.
    – Powerlord
    Jul 9, 2010 at 15:14
  • 2
    I believe RANU = run as normal user (e.g. msdn.microsoft.com/en-us/library/bb932482(VS.90).aspx). Which is at best a complement to AV, not a replacement. Jul 9, 2010 at 15:16

3 Answers 3

15

Looks like another application or process is reading or monitoring the files being written and ignoring .txt or .log files for performance reason.

Why ? Because your bunch of code, when run on my laptop, give same results for all the files (22 seconds), without any variations.

1
  • Wow i would never have though about my antivirus, thx for the quick answer Jul 9, 2010 at 15:31
6

I tested this on my work machine; a Core 2 machine with 32-bit Windows XP with Symantec Endpoint Protection AV installed. These are my results:

abc.txt:                00:00:07.1192029  
abc.txt.01564611564:    00:00:06.9956377  
abc.01564611564.txt:    00:00:06.9534773  
abc.xml:                00:00:06.9368894  
abc.xml.01564611564:    00:00:07.9326258  
abc.config:             00:00:07.9074675  
abc.config.01564611564: 00:00:08.0205423  
abc.exe:                00:00:21.2559372  
abc.exe.01564611564:    00:00:07.2417322  
abc.log:                00:00:07.0871043  
abc.log.01564611564:    00:00:07.1848522

In my case, it was only the .exe extension that took longer.

So yes, at a guess, the anti-virus is interfering with write speeds.

Edit: I should note, this user is a Limited User on an AD domain.

5

As Orsol suggested, your AV may be ignoring txt and log files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.