Thread: Multiple Pages in a Txt File

  1. #31
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I ran your example of 100MB as well, and there is a difference, but far from 3x:
    Code:
    // Using fputc()
    TestCRT             : Ticks=12281
    TestCRT             : Ticks=14359
    TestCRT             : Ticks=12390
    TestCRT             : Ticks=15875
    // Using fwrite() with buffer
    TestCRT2            : Ticks=13750
    TestCRT2            : Ticks=14109
    TestCRT2            : Ticks=12219
    TestCRT2            : Ticks=14437
    // Using WriteFile() with buffer. 
    TestMyCode2         : Ticks=10922
    TestMyCode2         : Ticks=11250
    TestMyCode2         : Ticks=10531
    TestMyCode2         : Ticks=10485
    It is fairly obvious that this is much more dependant on the speed of the hard-disk and the IO transfer rate than the C runtime library.

    For VERY obvious reasons, I didn't run the original "write one byte at a time through WriteFile", as that's not sensible for this size of file.

    You aren't running the DEBUG version of the CRT by any chance?

    --
    Mats

  2. #32
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by matsp View Post
    It is fairly obvious that this is much more dependant on the speed of the hard-disk and the IO transfer rate than the C runtime library.
    Of course it is... maybe my hard drive is faster than I think and more % of time goes to code execution than for you?
    Quote Originally Posted by matsp View Post
    For VERY obvious reasons, I didn't run the original "write one byte at a time through WriteFile", as that's not sensible for this size of file.
    That's amusingly stupid piece of code, lol.
    Quote Originally Posted by matsp View Post
    You aren't running the DEBUG version of the CRT by any chance?
    No way. I even disassembled my program and it is certainly calling the correct (non-debug) CRT functions from msvcrt.dll.

    I think all of this is more of a personal taste (and time). I like ultra-high performance and I like to do it in C rather than in Assembly. I hope you don't mind if I continue writing WinAPI code?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #33
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by maxorator View Post
    Well, we can agree that in normal situations it is recommended to use CRT and that direct Win32 API is good if you know exactly what you're doing, have a lot of time and want high performance. But when dealing with GUI the portability is already lost and then it only matters how much time you have available to spend on the project...
    The "know exactly what you're doing" is a key here - for example, if you call the Win32 API with "bad" parameters, then you get slow performance by a factor or about 50, compared to the C-runtime, and although you have shown a factor of about 3 difference, it's still a small difference compared to the "bad case" I've shown.

    So, I completely agree, using the Win32 API requires knowledge about how it works, whilst the C-runtime is much more forgiving in it's implementation.

    --
    Mats

  4. #34
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I hope you don't mind if I continue writing WinAPI code?
    If you're so concerned with efficiency and non-portability, why not go a step further and write everything in assembly?

    Don't optimize prematurely: It is far, far easier to make a correct program fast than it is to make a fast program correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM