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 | 26 | |
| 27 | 27 | /* Tests based on PI-MBUS-300 documentation */ |
| 28 | 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 | 35 | struct timeval tv; |
| 35 | 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 | 41 | int main(void) |
| ... | ... | @@ -69,20 +70,20 @@ int main(void) |
| 69 | 70 | printf("READ COIL STATUS\n\n"); |
| 70 | 71 | |
| 71 | 72 | nb_points = MAX_STATUS; |
| 72 | - start = gettime(); | |
| 73 | + start = gettime_ms(); | |
| 73 | 74 | for (i=0; i<NB_LOOPS; i++) { |
| 74 | 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 | 81 | printf("Transfert rate in points/seconds:\n"); |
| 81 | 82 | printf("* %'d points/s\n", rate); |
| 82 | 83 | printf("\n"); |
| 83 | 84 | |
| 84 | 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 | 87 | printf("Values:\n"); |
| 87 | 88 | printf("* %d x %d values\n", NB_LOOPS, nb_points); |
| 88 | 89 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| ... | ... | @@ -94,7 +95,7 @@ int main(void) |
| 94 | 95 | printf("Values and TCP Modbus overhead:\n"); |
| 95 | 96 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); |
| 96 | 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 | 99 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| 99 | 100 | printf("* %'d KiB/s\n", rate); |
| 100 | 101 | printf("\n\n"); |
| ... | ... | @@ -102,20 +103,20 @@ int main(void) |
| 102 | 103 | printf("READ HOLDING REGISTERS\n\n"); |
| 103 | 104 | |
| 104 | 105 | nb_points = MAX_REGISTERS; |
| 105 | - start = gettime(); | |
| 106 | + start = gettime_ms(); | |
| 106 | 107 | for (i=0; i<NB_LOOPS; i++) { |
| 107 | 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 | 114 | printf("Transfert rate in points/seconds:\n"); |
| 114 | 115 | printf("* %'d registers/s\n", rate); |
| 115 | 116 | printf("\n"); |
| 116 | 117 | |
| 117 | 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 | 120 | printf("Values:\n"); |
| 120 | 121 | printf("* %d x %d values\n", NB_LOOPS, nb_points); |
| 121 | 122 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| ... | ... | @@ -127,7 +128,7 @@ int main(void) |
| 127 | 128 | printf("Values and TCP Modbus overhead:\n"); |
| 128 | 129 | printf("* %d x %d bytes\n", NB_LOOPS, bytes); |
| 129 | 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 | 132 | printf("* %.3f ms for %d bytes\n", elapsed, bytes); |
| 132 | 133 | printf("* %'d KiB/s\n", rate); |
| 133 | 134 | printf("\n"); | ... | ... |