Commit 795d1fd71dc4862b239cce0eddf77f8b4ae29f71
1 parent
92f7a1f8
Fix the bandwith computing when a longer delay is measured
- use milliseconds instead of microseconds - increase the number of loops to 100 000 from 10 000
Showing
1 changed file
with
17 additions
and
16 deletions
tests/bandwidth-master.c
| @@ -26,15 +26,16 @@ | @@ -26,15 +26,16 @@ | ||
| 26 | 26 | ||
| 27 | /* Tests based on PI-MBUS-300 documentation */ | 27 | /* Tests based on PI-MBUS-300 documentation */ |
| 28 | #define SLAVE 0x11 | 28 | #define SLAVE 0x11 |
| 29 | -#define NB_LOOPS 10000 | 29 | +#define NB_LOOPS 100000 |
| 30 | 30 | ||
| 31 | -#define G_USEC_PER_SEC 1000000 | ||
| 32 | -uint32_t gettime(void) | 31 | +#define G_MSEC_PER_SEC 1000 |
| 32 | + | ||
| 33 | +uint32_t gettime_ms(void) | ||
| 33 | { | 34 | { |
| 34 | struct timeval tv; | 35 | struct timeval tv; |
| 35 | gettimeofday (&tv, NULL); | 36 | gettimeofday (&tv, NULL); |
| 36 | 37 | ||
| 37 | - return (uint32_t) tv.tv_sec * G_USEC_PER_SEC + tv.tv_usec; | 38 | + return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | int main(void) | 41 | int main(void) |
| @@ -69,20 +70,20 @@ int main(void) | @@ -69,20 +70,20 @@ int main(void) | ||
| 69 | printf("READ COIL STATUS\n\n"); | 70 | printf("READ COIL STATUS\n\n"); |
| 70 | 71 | ||
| 71 | nb_points = MAX_STATUS; | 72 | nb_points = MAX_STATUS; |
| 72 | - start = gettime(); | 73 | + start = gettime_ms(); |
| 73 | for (i=0; i<NB_LOOPS; i++) { | 74 | for (i=0; i<NB_LOOPS; i++) { |
| 74 | ret = read_coil_status(&mb_param, SLAVE, 0, nb_points, tab_rp_status); | 75 | ret = read_coil_status(&mb_param, SLAVE, 0, nb_points, tab_rp_status); |
| 75 | } | 76 | } |
| 76 | - end = gettime(); | ||
| 77 | - elapsed = (end - start) / 1000; | 77 | + end = gettime_ms(); |
| 78 | + elapsed = end - start; | ||
| 78 | 79 | ||
| 79 | - rate = (NB_LOOPS * nb_points) * G_USEC_PER_SEC / (end - start); | 80 | + rate = (NB_LOOPS * nb_points) * G_MSEC_PER_SEC / (end - start); |
| 80 | printf("Transfert rate in points/seconds:\n"); | 81 | printf("Transfert rate in points/seconds:\n"); |
| 81 | printf("* %'d points/s\n", rate); | 82 | printf("* %'d points/s\n", rate); |
| 82 | printf("\n"); | 83 | printf("\n"); |
| 83 | 84 | ||
| 84 | bytes = NB_LOOPS * (nb_points / 8) + ((nb_points % 8) ? 1 : 0); | 85 | bytes = NB_LOOPS * (nb_points / 8) + ((nb_points % 8) ? 1 : 0); |
| 85 | - rate = bytes / 1024 * G_USEC_PER_SEC / (end - start); | 86 | + rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); |
| 86 | printf("Values:\n"); | 87 | printf("Values:\n"); |
| 87 | printf("* %d x %d values\n", NB_LOOPS, nb_points); | 88 | printf("* %d x %d values\n", NB_LOOPS, nb_points); |
| 88 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); | 89 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| @@ -94,7 +95,7 @@ int main(void) | @@ -94,7 +95,7 @@ int main(void) | ||
| 94 | printf("Values and TCP Modbus overhead:\n"); | 95 | printf("Values and TCP Modbus overhead:\n"); |
| 95 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); | 96 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); |
| 96 | bytes = NB_LOOPS * bytes; | 97 | bytes = NB_LOOPS * bytes; |
| 97 | - rate = bytes / 1024 * G_USEC_PER_SEC / (end - start); | 98 | + rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); |
| 98 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); | 99 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| 99 | printf("* %'d KiB/s\n", rate); | 100 | printf("* %'d KiB/s\n", rate); |
| 100 | printf("\n\n"); | 101 | printf("\n\n"); |
| @@ -102,20 +103,20 @@ int main(void) | @@ -102,20 +103,20 @@ int main(void) | ||
| 102 | printf("READ HOLDING REGISTERS\n\n"); | 103 | printf("READ HOLDING REGISTERS\n\n"); |
| 103 | 104 | ||
| 104 | nb_points = MAX_REGISTERS; | 105 | nb_points = MAX_REGISTERS; |
| 105 | - start = gettime(); | 106 | + start = gettime_ms(); |
| 106 | for (i=0; i<NB_LOOPS; i++) { | 107 | for (i=0; i<NB_LOOPS; i++) { |
| 107 | ret = read_holding_registers(&mb_param, SLAVE, 0, nb_points, tab_rp_registers); | 108 | ret = read_holding_registers(&mb_param, SLAVE, 0, nb_points, tab_rp_registers); |
| 108 | } | 109 | } |
| 109 | - end = gettime(); | ||
| 110 | - elapsed = (end - start) / 1000; | 110 | + end = gettime_ms(); |
| 111 | + elapsed = end - start; | ||
| 111 | 112 | ||
| 112 | - rate = (NB_LOOPS * nb_points) * G_USEC_PER_SEC / (end - start); | 113 | + rate = (NB_LOOPS * nb_points) * G_MSEC_PER_SEC / (end - start); |
| 113 | printf("Transfert rate in points/seconds:\n"); | 114 | printf("Transfert rate in points/seconds:\n"); |
| 114 | printf("* %'d registers/s\n", rate); | 115 | printf("* %'d registers/s\n", rate); |
| 115 | printf("\n"); | 116 | printf("\n"); |
| 116 | 117 | ||
| 117 | bytes = NB_LOOPS * nb_points * sizeof(uint16_t); | 118 | bytes = NB_LOOPS * nb_points * sizeof(uint16_t); |
| 118 | - rate = bytes / 1024 * G_USEC_PER_SEC / (end - start); | 119 | + rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); |
| 119 | printf("Values:\n"); | 120 | printf("Values:\n"); |
| 120 | printf("* %d x %d values\n", NB_LOOPS, nb_points); | 121 | printf("* %d x %d values\n", NB_LOOPS, nb_points); |
| 121 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); | 122 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| @@ -127,7 +128,7 @@ int main(void) | @@ -127,7 +128,7 @@ int main(void) | ||
| 127 | printf("Values and TCP Modbus overhead:\n"); | 128 | printf("Values and TCP Modbus overhead:\n"); |
| 128 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); | 129 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); |
| 129 | bytes = NB_LOOPS * bytes; | 130 | bytes = NB_LOOPS * bytes; |
| 130 | - rate = bytes / 1024 * G_USEC_PER_SEC / (end - start); | 131 | + rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); |
| 131 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); | 132 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| 132 | printf("* %'d KiB/s\n", rate); | 133 | printf("* %'d KiB/s\n", rate); |
| 133 | printf("\n"); | 134 | printf("\n"); |