Exemple #1
0
int main(int argc, char **argv)
{
    char mode;
    int fsize;
    struct timeval start;
    double dur;
    char *filepath, *filepaths, *tofree;
    Performance perf;

    if ( argc != 6 ) {
        cout << "usage: ./me r|w filepaths filesize addition-head additional-datarow" << endl;
        cout << "example: ./perform w /tmp/myfile1,/tmp/myfile2 1024 'hello hellodata' 'echo echodata'" << endl;
        exit(1);
    }
    
    mode = argv[1][0];
    tofree = filepaths = strdup(argv[2]);
    fsize = atoi(argv[3]);
    
    start_timer(&start);

    while ((filepath = strsep(&filepaths, ",")) != NULL) {
        if ( mode == 'r' )
            readfile(filepath, fsize);
        else
            writefile(filepath, fsize);
    }

    dur = end_timer_get_duration(&start);

    perf.put("duration", dur);
    perf.put("filesize", fsize);
    perf.put("mode", argv[1]);
    perf.put(argv[4], argv[5]);
    cout << perf.showColumns();

    free(tofree);
}