/alps/fwbench

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/fwbench

« back to all changes in this revision

Viewing changes to seqreader.c

  • Committer: Suren A. Chilingaryan
  • Date: 2012-03-23 02:39:12 UTC
  • Revision ID: csa@dside.dyndns.org-20120323023912-w5dm157cf01nyhcm
seqreader

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/types.h>
 
4
#include <sys/stat.h>
 
5
#include <sys/time.h>
 
6
#include <unistd.h>
 
7
#include <dirent.h>
 
8
 
 
9
#define BUFSIZE 65536
 
10
 
 
11
int main(int argc, char *argv[]) {
 
12
    int err;
 
13
    size_t SKIP = 1;
 
14
    DIR *dir;
 
15
    struct dirent *ent;
 
16
    struct timeval start, tv;
 
17
    size_t us;
 
18
    size_t files = 0;
 
19
    size_t total_size = 0;
 
20
    size_t skip;
 
21
    size_t run;
 
22
    char buffer[65536];
 
23
    
 
24
    if (argc < 2) {
 
25
        printf("Usage: %s <directory> [skip]\n", argv[0]);
 
26
        exit(0);
 
27
    }
 
28
    
 
29
    chdir(argv[1]);
 
30
 
 
31
    if (argc > 2) {
 
32
        SKIP = atoi(argv[2]);
 
33
        
 
34
        printf("Skip %i\n", SKIP);
 
35
    }
 
36
 
 
37
    gettimeofday(&start, NULL);
 
38
    for (run = 0; run < SKIP; run++) {
 
39
      skip = 0;
 
40
      dir = opendir(".");
 
41
      while (ent = readdir(dir)) {
 
42
        struct stat st;
 
43
        
 
44
        if (((skip++)%SKIP) != run) continue;
 
45
 
 
46
        if (stat(ent->d_name, &st)) continue;
 
47
        if (!S_ISREG(st.st_mode)) continue;
 
48
        
 
49
        FILE *f = fopen(ent->d_name, "r");
 
50
        if (!f) continue;
 
51
        
 
52
        int size = st.st_blksize;
 
53
        
 
54
        if (size > BUFSIZE) {
 
55
            printf("Buffer too small\n");
 
56
            exit(1);
 
57
        }
 
58
        
 
59
        while (!feof(f)) {
 
60
            err = fread(buffer, 1, size, f);
 
61
            if (err < 0) {
 
62
                printf("Read failed\n");
 
63
                exit(1);
 
64
            }
 
65
        }
 
66
        
 
67
        fclose(f);
 
68
 
 
69
        total_size += st.st_size;
 
70
        files++;
 
71
        
 
72
        gettimeofday(&tv, NULL);
 
73
        us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
 
74
        printf("Reading: %s (%lu MB), Read: %lu files (%lu GB),  Measured speed: %lu mB/s\n", ent->d_name, st.st_size/1024/1024, files, total_size / 1024 / 1024 / 1024, total_size / us);
 
75
      }
 
76
      closedir(dir);
 
77
    }
 
78
 
 
79
}
 
 
b'\\ No newline at end of file'