Commit baa0cbaa7359fd0ba94344e18258b908c83b9667

Authored by Arezki AIT MOUHEB
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 4 #include <stdlib.h>
5 5  
6 6 // Conditionals
7   -const bool IS_DEBUG = false;
  7 +const bool IS_DEBUG = true;
8 8  
9 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 12 const char CSV_DELIMITERS[] = ",";
13 13  
14 14 // Globals
15 15 char** CSV_HEADER_FIELDS;
16 16 unsigned int CSV_NB_FIELDS;
17 17  
  18 +
  19 +//########################################################################
18 20 void display_header()
19 21 {
20 22 for(unsigned int i = 0; i < CSV_NB_FIELDS; i++)
... ... @@ -23,6 +25,8 @@ void display_header()
23 25 }
24 26 }
25 27  
  28 +
  29 +//########################################################################
26 30 void read_csv_header(char * header_line)
27 31 {
28 32 int line_length = strlen(header_line);
... ... @@ -41,6 +45,7 @@ void read_csv_header(char * header_line)
41 45 }
42 46  
43 47 // Globals allocation
  48 + if (IS_DEBUG) printf("number of fields: %d\n",nb_fields); // TO BE REMOVED LATER
44 49 CSV_NB_FIELDS = nb_fields;
45 50 CSV_HEADER_FIELDS = malloc( nb_fields * sizeof(char*) );
46 51  
... ... @@ -58,6 +63,7 @@ void read_csv_header(char * header_line)
58 63 if (IS_DEBUG) display_header();
59 64 }
60 65  
  66 +//########################################################################
61 67 void read_csv_file(const char * filename)
62 68 {
63 69 FILE* fp = fopen(filename, "r");
... ... @@ -98,11 +104,13 @@ void read_csv_file(const char * filename)
98 104 fclose(fp);
99 105 }
100 106  
  107 +//########################################################################
101 108 void usage(const char * prog_name)
102 109 {
103 110 printf("Usage is %s your_csv_file\n\n", prog_name);
104 111 }
105 112  
  113 +//########################################################################
106 114 int main(int argc, char * argv[])
107 115 {
108 116 if (2 != argc)
... ...