Thread: FILES in WinAPI

  1. #46 JasonD's Avatar
    Join Date
    Mar 2003
    Originally posted by JasonD
    I will try and find some time to modify this test to allow changing the data, and writing it back to memory, using a simple memory manager, much like a real world application would. I think this test, when finished, will show the most accurate results of emulating a real world situation.
    I have created another test that emulates a memory manager. The program allocates 50% of available unused RAM for its memory cache. It reads/writes sections from/to the file, but never re-reads in a section from the file that is already cached (the win32 API has proven to be much better at re-reading unchanged data from a file multiple times, but you should never have to do this, so it is meaningless). It only writes out a section when it needs space for a read. It runs on the basis of last access - the last accessed section in cache is the one written out, before reading in a new section that has not been cached, yet. The program choses random sections, but does so in a way that certain sections are accessed more often, just as would happen in a real world application. The program does not modify the data to ensure that this would not interfere with the timing. I use the high resolution performance counter, which is more accurate than 1 ms. Times are rounded off to 1 ms.

    The results are below:
    File Access Speed Test - C Runtime vs. Win32 API - By: Jason Doucette
    --> Random Access Read/Write test.
    Total size of physical memory = 536334336 bytes = 511.5 MB.
    Size of physical memory available = 359559168 bytes = 342.9 MB.
    File sizes = 253822000 bytes = 242.1 MB.
    Buffer size = 1048576 bytes = 1 MB.
    Number of full buffer-sized sections in file = 242.
    Percentage of available memory used for memory cache = 50%
    Number of buffers in memory cache = 171
    Size of memory cache = 179306496 bytes = 171 MB.
    Number of random read/write sections to be performed per test = 8192
    type:       C       C       C   Win32   Win32   Win32   C spd   C spd   C spd
    test:      rb     rbS     rbR       0     SEQ    RAND  % of W  % of W  % of W
     # 1: 57284ms 64514ms 26739ms 25414ms 72988ms 17759ms     44%    113%     66%
     # 2: 18625ms 63979ms 15700ms 22359ms 61082ms 16932ms    120%     95%    107%
     # 3: 17364ms 65151ms 15914ms 16696ms 66792ms 16236ms     96%    102%    102%
     # 4: 17294ms 63841ms 16700ms 16790ms 60186ms 15924ms     97%     94%     95%
     # 5: 19296ms 62884ms 15782ms 16540ms 63671ms 16016ms     85%    101%    101%
     # 6: 16932ms 64949ms 16284ms 16280ms 60153ms 16424ms     96%     92%    100%
     # 7: 19418ms 61968ms 15725ms 16646ms 63889ms 16013ms     85%    103%    101%
     # 8: 17443ms 65307ms 16108ms 16172ms 59846ms 18576ms     92%     91%    115%
     # 9: 17500ms 62046ms 15726ms 16329ms 63671ms 15986ms     93%    102%    101%
     #10: 17589ms 65497ms 15814ms 16625ms 62869ms 16458ms     94%     95%    104%
     #11: 17767ms 62268ms 15974ms 21721ms 60498ms 15919ms    122%     97%     99%
     #12: 17565ms 65412ms 15870ms 16301ms 63089ms 16274ms     92%     96%    102%
     #13: 17205ms 61683ms 18153ms 16837ms 60411ms 15883ms     97%     97%     87%
     #14: 17232ms 65461ms 15817ms 16442ms 63350ms 16103ms     95%     96%    101%
     #15: 17203ms 64999ms 16359ms 16607ms 60292ms 15981ms     96%     92%     97%
     #16: 21799ms 62399ms 15706ms 16363ms 63456ms 16046ms     75%    101%    102%
     #17: 17402ms 65582ms 15929ms 16545ms 59884ms 18170ms     95%     91%    114%
     #18: 17892ms 62801ms 15697ms 16429ms 64675ms 16102ms     91%    102%    102%
     #19: 17660ms 70109ms 15803ms 16467ms 62738ms 16475ms     93%     89%    104%
     #20: 17412ms 61752ms 16686ms 17210ms 63147ms 15996ms     98%    102%     95%
     #21: 17600ms 65842ms 15784ms 16650ms 63457ms 16218ms     94%     96%    102%
     #22: 17212ms 66307ms 16386ms 17067ms 60263ms 15913ms     99%     90%     97%
     #23: 19320ms 63085ms 15837ms 16534ms 64138ms 16104ms     85%    101%    101%
     #24: 17367ms 64699ms 16144ms 16844ms 60044ms 15979ms     96%     92%     98%
     #25: 20242ms 64575ms 15780ms 16788ms 63257ms 15929ms     82%     97%    100%
     #26: 17468ms 65774ms 15962ms 16617ms 62722ms 17926ms     95%     95%    112%
     #27: 17607ms 62195ms 15693ms 18479ms 61087ms 16040ms    104%     98%    102%
     #28: 17115ms 67016ms 15881ms 16363ms 64190ms 16501ms     95%     95%    103%
     #29: 17818ms 61585ms 17046ms 17191ms 62555ms 16328ms     96%    101%     95%
     #30: 18077ms 65391ms 15782ms 16842ms 63468ms 16240ms     93%     97%    102%
     #31: 17491ms 64148ms 17964ms 16605ms 60239ms 15978ms     94%     93%     88%
     #32: 20153ms 62823ms 15703ms 16736ms 63519ms 16312ms     83%    101%    103%
    avg:  19229ms 64251ms 16451ms 17296ms 62675ms 16398ms     89%     97%     99%
    Please note that, again, I test all three possibilities of access for the C runtime library, and for the Win32 API. The only one that actually matters is the random access (i.e. the 3rd one, the ones that are bolded), because this is what we are doing. You'll see that the results for C runtime and Win32 API are the same - within 1% of each other (99% means the C runtime went 99% of the speed of the win32 API).

    C runtime may actually be a bit faster, if you ignore the first rep (I think the first rep may show slower times than normal since I locked my workstation when the test started), as there are mostly high 15Ks for C runtime, and mostly low 16Ks for Win32 API, which are the best times for both sides. You can see by the percentage comparison that the C runtime is quicker for the majority of the tests than the Win32 API.

    Conclusion: It looks to me that there is no advantage to using the Win32 API over the C Runtime library. I would personally still use wrappers, anyway, so what you use under those wrappers is completely up to you.

  2. #47
    Registered User
    Join Date
    Jun 2003
    Thanks for all the work you have put in Jason. I reckon this post should be saved as it's a good reference for people deciding on there implementation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM