Commit baa0cbaa7359fd0ba94344e18258b908c83b9667
1 parent
56f74995
Optimisation du BUFFER_SIZE
Showing
1 changed file
with
11 additions
and
3 deletions
Show diff stats
src/csv_reader.c
@@ -4,17 +4,19 @@ | @@ -4,17 +4,19 @@ | ||
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | 5 | ||
6 | // Conditionals | 6 | // Conditionals |
7 | -const bool IS_DEBUG = false; | 7 | +const bool IS_DEBUG = true; |
8 | 8 | ||
9 | // Constants | 9 | // Constants |
10 | -const unsigned int BUFFER_SIZE = 2048; | ||
11 | -const unsigned int FIELD_SIZE = 20; | 10 | +const unsigned int BUFFER_SIZE = 620; // (FIELD SIZE = 20) x (NUMBER OF FIELDS = 31) = 620 BYTES // OPTIMIZATION |
11 | +const unsigned int FIELD_SIZE = 20; // NUMBER OF CHAR PER FIELD | ||
12 | const char CSV_DELIMITERS[] = ","; | 12 | const char CSV_DELIMITERS[] = ","; |
13 | 13 | ||
14 | // Globals | 14 | // Globals |
15 | char** CSV_HEADER_FIELDS; | 15 | char** CSV_HEADER_FIELDS; |
16 | unsigned int CSV_NB_FIELDS; | 16 | unsigned int CSV_NB_FIELDS; |
17 | 17 | ||
18 | + | ||
19 | +//######################################################################## | ||
18 | void display_header() | 20 | void display_header() |
19 | { | 21 | { |
20 | for(unsigned int i = 0; i < CSV_NB_FIELDS; i++) | 22 | for(unsigned int i = 0; i < CSV_NB_FIELDS; i++) |
@@ -23,6 +25,8 @@ void display_header() | @@ -23,6 +25,8 @@ void display_header() | ||
23 | } | 25 | } |
24 | } | 26 | } |
25 | 27 | ||
28 | + | ||
29 | +//######################################################################## | ||
26 | void read_csv_header(char * header_line) | 30 | void read_csv_header(char * header_line) |
27 | { | 31 | { |
28 | int line_length = strlen(header_line); | 32 | int line_length = strlen(header_line); |
@@ -41,6 +45,7 @@ void read_csv_header(char * header_line) | @@ -41,6 +45,7 @@ void read_csv_header(char * header_line) | ||
41 | } | 45 | } |
42 | 46 | ||
43 | // Globals allocation | 47 | // Globals allocation |
48 | + if (IS_DEBUG) printf("number of fields: %d\n",nb_fields); // TO BE REMOVED LATER | ||
44 | CSV_NB_FIELDS = nb_fields; | 49 | CSV_NB_FIELDS = nb_fields; |
45 | CSV_HEADER_FIELDS = malloc( nb_fields * sizeof(char*) ); | 50 | CSV_HEADER_FIELDS = malloc( nb_fields * sizeof(char*) ); |
46 | 51 | ||
@@ -58,6 +63,7 @@ void read_csv_header(char * header_line) | @@ -58,6 +63,7 @@ void read_csv_header(char * header_line) | ||
58 | if (IS_DEBUG) display_header(); | 63 | if (IS_DEBUG) display_header(); |
59 | } | 64 | } |
60 | 65 | ||
66 | +//######################################################################## | ||
61 | void read_csv_file(const char * filename) | 67 | void read_csv_file(const char * filename) |
62 | { | 68 | { |
63 | FILE* fp = fopen(filename, "r"); | 69 | FILE* fp = fopen(filename, "r"); |
@@ -98,11 +104,13 @@ void read_csv_file(const char * filename) | @@ -98,11 +104,13 @@ void read_csv_file(const char * filename) | ||
98 | fclose(fp); | 104 | fclose(fp); |
99 | } | 105 | } |
100 | 106 | ||
107 | +//######################################################################## | ||
101 | void usage(const char * prog_name) | 108 | void usage(const char * prog_name) |
102 | { | 109 | { |
103 | printf("Usage is %s your_csv_file\n\n", prog_name); | 110 | printf("Usage is %s your_csv_file\n\n", prog_name); |
104 | } | 111 | } |
105 | 112 | ||
113 | +//######################################################################## | ||
106 | int main(int argc, char * argv[]) | 114 | int main(int argc, char * argv[]) |
107 | { | 115 | { |
108 | if (2 != argc) | 116 | if (2 != argc) |