testing read/write speed

Discussion in 'C++' started by Gernot Frisch, Aug 29, 2006.

  1. Hi,

    I want to have a representative information about the read and write
    speeds of a drive (cf-card, HDD and RAM-Disk).
    I think the buffering of the filesystem must be fooled somehow for my
    test program (sorry, uses GetTickCount() == Win32 for Milliseconds)


    # # #

    // E:\\Temp\\ (HardDisk) Write: 9761.29KB/s, Read: 371794.26KB/s
    // R:\\ (RamDrive) Write: 144010.44KB/s, Read: 372827.02KB/s

    #include <stdio.h>

    #define FBUFSIZ (1024*1024*8) // 8Meg
    #define LOOPS 16
    #define TESTFILE "R:\\test.txt"
    int main(int, char**)
    {
    char* buffer = new char[FBUFSIZ];
    DWORD start, end1, end2;
    // make sure memory is there
    for(int i=0; i<FBUFSIZ; ++i)
    buffer=(char)i;
    start = ::GetTickCount();

    // Write test
    for(int i=0; i<LOOPS; ++i)
    {
    FILE* pF = fopen(TESTFILE, "wb");
    fwrite(buffer, FBUFSIZ, 1, pF);
    fclose(pF);
    }
    end1 = ::GetTickCount();

    // Read test
    for(int i=0; i<LOOPS; ++i)
    {
    FILE* pF = fopen(TESTFILE, "rb");
    fread(buffer, FBUFSIZ, 1, pF);
    fclose(pF);
    }
    end2 = ::GetTickCount();

    printf("Write: %.2fKB/s, Read: %.2fKB/s\n",
    (double)FBUFSIZ*LOOPS/(end1-start),
    (double)FBUFSIZ*LOOPS/(end2-end1));
    buffer[0] = 1;

    delete[] buffer;
    }

    # # #




    --
    -Gernot
    int main(int argc, char** argv) {printf
    ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
    Gernot Frisch, Aug 29, 2006
    #1
    1. Advertising

  2. Gernot Frisch wrote:
    > I want to have a representative information about the read and write
    > speeds of a drive (cf-card, HDD and RAM-Disk).
    > I think the buffering of the filesystem must be fooled somehow for my
    > test program (sorry, uses GetTickCount() == Win32 for Milliseconds)
    > [...]


    Thanks for sharing.

    Are you seeking comments? I/O performance is platform-specific, and
    has no relation to the language or the library. The Standard imposes
    no requirements on I/O performance. That's my $0.02.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 29, 2006
    #2
    1. Advertising

  3. "Victor Bazarov" <> schrieb im Newsbeitrag
    news:ed1bee$ndh$...
    > Gernot Frisch wrote:
    >> I want to have a representative information about the read and
    >> write
    >> speeds of a drive (cf-card, HDD and RAM-Disk).
    >> I think the buffering of the filesystem must be fooled somehow for
    >> my
    >> test program (sorry, uses GetTickCount() == Win32 for Milliseconds)
    >> [...]

    >
    > Thanks for sharing.
    >
    > Are you seeking comments? I/O performance is platform-specific, and
    > has no relation to the language or the library. The Standard
    > imposes
    > no requirements on I/O performance. That's my $0.02.


    The read speeds are always the same (300 MB/sec) which is in
    indication that this is propably not from disk.
    What might be an option to get true read speeds?
    Gernot Frisch, Aug 29, 2006
    #3
  4. Gernot Frisch wrote:
    > [..]
    > The read speeds are always the same (300 MB/sec) which is in
    > indication that this is propably not from disk.
    > What might be an option to get true read speeds?


    Ask in the newsgroup for your OS.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 29, 2006
    #4
  5. Gernot Frisch schrieb:
    > Hi,
    >
    > I want to have a representative information about the read and write
    > speeds of a drive (cf-card, HDD and RAM-Disk).
    > I think the buffering of the filesystem must be fooled somehow for my
    > test program (sorry, uses GetTickCount() == Win32 for Milliseconds)


    This is platform specific, you should ask in a windows platform group.
    Since this is not your first posting here, you should definitly now that.

    > #include <stdio.h>
    >
    > #define FBUFSIZ (1024*1024*8) // 8Meg
    > #define LOOPS 16
    > #define TESTFILE "R:\\test.txt"
    > int main(int, char**)
    > {
    > char* buffer = new char[FBUFSIZ];
    > DWORD start, end1, end2;
    > // make sure memory is there
    > for(int i=0; i<FBUFSIZ; ++i)
    > buffer=(char)i;
    > start = ::GetTickCount();

    [...]
    > delete[] buffer;
    > }


    Why do you use new[] and delete[] in an otherwise plain C programm?

    --
    Thomas
    Thomas J. Gritzan, Aug 29, 2006
    #5

  6. >> I think the buffering of the filesystem must be fooled somehow for
    >> my
    >> test program (sorry, uses GetTickCount() == Win32 for Milliseconds)

    >
    > This is platform specific, you should ask in a windows platform
    > group.
    > Since this is not your first posting here, you should definitly now
    > that.


    I didn't know it was platform specific - sorry.

    > [...]
    > Why do you use new[] and delete[] in an otherwise plain C programm?


    I use fopen/fread, since cin/cout are horribly slow on my compiler.
    I use printf because I don't know how to printf("%.2f", 0.0) in C++.
    All the rest *should* be C++.
    Gernot Frisch, Aug 29, 2006
    #6
  7. Gernot Frisch

    Ian Collins Guest

    Gernot Frisch wrote:
    > Hi,
    >
    > I want to have a representative information about the read and write
    > speeds of a drive (cf-card, HDD and RAM-Disk).
    > I think the buffering of the filesystem must be fooled somehow for my
    > test program (sorry, uses GetTickCount() == Win32 for Milliseconds)
    >

    Have a look at the source for bonnie++ to see how this should be done.

    --
    Ian Collins.
    Ian Collins, Aug 29, 2006
    #7

  8. > Have a look at the source for bonnie++ to see how this should be
    > done.


    thank you.
    Gernot Frisch, Aug 30, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ham

    I need speed Mr .Net....speed

    Ham, Oct 28, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,317
    Antony Baula
    Oct 29, 2004
  2. efiedler
    Replies:
    1
    Views:
    2,016
    Tim Ward
    Oct 9, 2003
  3. Jose
    Replies:
    10
    Views:
    619
    Andrew Thompson
    Jan 19, 2005
  4. Replies:
    2
    Views:
    2,269
    Howard
    Apr 28, 2004
  5. Replies:
    2
    Views:
    330
    Christopher Benson-Manica
    Apr 28, 2004
Loading...

Share This Page