Benchmark
 All Classes Files Functions Variables Typedefs Macros
Macros | Functions
file.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "benchmark.h"

Macros

#define MAX_SIZE   0x100000
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define MAX_SIZE   0x100000

Function Documentation

int main ( int  argc,
char *  argv[] 
)
11  {
12  timer *t = timer_alloc();
13  recorder *open_rec = recorder_alloc("open.csv");
14  recorder *write_rec = recorder_alloc("write.csv");
15  recorder *read_rec = recorder_alloc("read.csv");
16  recorder *close_rec = recorder_alloc("close.csv");
17 
18  int err, size;
19  ssize_t len;
20  start_timer(t);
21  int fd = open("tmp.dat", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
22  write_record(open_rec, 1, stop_timer(t));
23  if(fd == -1) {
24  perror("open");
25  exit(EXIT_FAILURE);
26  }
27  char *s = (char *) malloc((MAX_SIZE + 1) * sizeof(char));
28  memset(s, 0, MAX_SIZE + 1);
29  for (size = 1; size <= MAX_SIZE; size *= 2) {
30  start_timer(t);
31  len = write(fd, (void *) s, size);
32  write_record(write_rec, size, stop_timer(t));
33  if (len == -1) {
34  perror("write");
35  return EXIT_FAILURE;
36  }
37  }
38  int file_size = size - 1; // e.g. 1 + 2 + 4 + 8 + 16 = 32 - 1
39  start_timer(t);
40  err = close(fd);
41  write_record(close_rec, 1, stop_timer(t));
42  if (err == -1) {
43  perror("close");
44  exit(EXIT_FAILURE);
45  }
46 
47  // BEGIN
48  start_timer(t);
49  fd = open("tmp.dat", O_RDONLY);
50  write_record(open_rec, file_size, stop_timer(t));
51  if (fd == -1) {
52  perror("open");
53  exit(EXIT_FAILURE);
54  }
55  for (size = 1; size <= MAX_SIZE; size *= 2) {
56  start_timer(t);
57  len = read(fd, (void *) s, size);
58  write_record(read_rec, size, stop_timer(t));
59  if (len == -1) {
60  perror("read");
61  return EXIT_FAILURE;
62  }
63  }
64  start_timer(t);
65  err = close(fd);
66  write_record(close_rec, file_size, stop_timer(t));
67  if(err == -1){
68  perror("close");
69  exit(EXIT_FAILURE);
70  }
71  // END
72 
73  free(s);
74  recorder_free(open_rec);
75  recorder_free(write_rec);
76  recorder_free(read_rec);
77  recorder_free(close_rec);
78  timer_free(t);
79 
80  return EXIT_SUCCESS;
81 }
char s[1]
Definition: argfct.c:24
void timer_free(timer *t)
Retourne le temps en nanosecondes depuis le début de mesure dans t
Definition: benchmark.c:172
recorder écrit les temps dans un fichier .csv
Definition: benchmark.c:208
#define MAX_SIZE
Definition: file.c:9
void write_record(recorder *rec, long int x, long int time)
Écris le temps time en correspondance avec x
Definition: benchmark.c:245
timer permet de mesurer le temps écoulé entre deux moments
Definition: benchmark.c:43
timer * t
Definition: memfork.c:25
void start_timer(timer *t)
Stoque le temps actuel comme début de la mesure dans t
Definition: benchmark.c:87
recorder * recorder_alloc(char *filename)
Alloue un recorder
Definition: benchmark.c:219
void recorder_free(recorder *rec)
Libère toutes les resources utilisées par rec
Definition: benchmark.c:263
timer * timer_alloc()
Alloue un timer
Definition: benchmark.c:63
long int stop_timer(timer *t)
Retourne le temps en nanosecondes depuis le début de mesure dans t
Definition: benchmark.c:133