Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define KILOBYTE 1024
- static const unsigned long long ITERATIONS = 115;
- static const unsigned long long BUFFER_SIZE = 4 * KILOBYTE;
- int main() {
- char buffer[ BUFFER_SIZE ];
- char* name = "/tmp/somefile";
- FILE* file = fopen( name, "r+");
- long long size = 0;
- long long read = 0;
- long long random = 0;
- long long i = 0;
- if( file == NULL ) return -1;
- fseek( file, 0, SEEK_END );
- size = ftell( file );
- rewind( file );
- if( size <= BUFFER_SIZE ) return -1;
- srand( time( NULL ) );
- for( ; i < ITERATIONS; ++i ) {
- random = ( long long )rand() + ( long long )rand() * 0xFFFFFFFF;
- random %= (size - BUFFER_SIZE);
- //if( ((random * 100) / size) < 40 ) {
- // --i;
- // continue;
- //}
- fseek( file, random, SEEK_SET );
- read = fread( buffer, 1, BUFFER_SIZE, file );
- printf( "Reading 4KB from %lli, read %lli, as far as %lli perc.\n", random, read, (random * 100) / size );
- }
- fclose( file );
- return 0;
- }
Add Comment
Please, Sign In to add comment