![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
elapsed_timer.cpp@136:2da626f30efa, 2015-09-14 (annotated)
- Committer:
- klauss
- Date:
- Mon Sep 14 14:05:43 2015 +0000
- Revision:
- 136:2da626f30efa
Adicionando funcionalidades de medi??o de tempo gasto em computa??es.; Criado fun??es especificar pra esta finalidade.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 136:2da626f30efa | 1 | %: include "elapsed_timer.h" |
klauss | 136:2da626f30efa | 2 | |
klauss | 136:2da626f30efa | 3 | bool boolInit_test = true; |
klauss | 136:2da626f30efa | 4 | bool boolEnd_test = false; |
klauss | 136:2da626f30efa | 5 | |
klauss | 136:2da626f30efa | 6 | bool boolInit_test_mean = true; |
klauss | 136:2da626f30efa | 7 | bool boolEnd_test_mean = false; |
klauss | 136:2da626f30efa | 8 | |
klauss | 136:2da626f30efa | 9 | Timer elapsed_timer; |
klauss | 136:2da626f30efa | 10 | Timer elapsed_timer_mean; |
klauss | 136:2da626f30efa | 11 | |
klauss | 136:2da626f30efa | 12 | uint16_t u16Elapsed_time_count = u16_ELAPSED_TIME_COUNT_TIMES; |
klauss | 136:2da626f30efa | 13 | |
klauss | 136:2da626f30efa | 14 | uint64_t u64Elapsed_time_u_sum = 0; |
klauss | 136:2da626f30efa | 15 | |
klauss | 136:2da626f30efa | 16 | void elapsed_time_start ( void ) |
klauss | 136:2da626f30efa | 17 | { |
klauss | 136:2da626f30efa | 18 | elapsed_timer.start (); |
klauss | 136:2da626f30efa | 19 | elapsed_timer.reset (); |
klauss | 136:2da626f30efa | 20 | } |
klauss | 136:2da626f30efa | 21 | |
klauss | 136:2da626f30efa | 22 | int elapsed_time_end ( void ) |
klauss | 136:2da626f30efa | 23 | { |
klauss | 136:2da626f30efa | 24 | elapsed_timer.stop (); |
klauss | 136:2da626f30efa | 25 | |
klauss | 136:2da626f30efa | 26 | int u_elapsed_time = elapsed_timer.read_us (); |
klauss | 136:2da626f30efa | 27 | |
klauss | 136:2da626f30efa | 28 | vz_printf ( "Elapsed_time : [ %du, %dm, %ds ]", |
klauss | 136:2da626f30efa | 29 | |
klauss | 136:2da626f30efa | 30 | u_elapsed_time, elapsed_timer.read_ms (), int ( elapsed_timer.read () ) ); |
klauss | 136:2da626f30efa | 31 | |
klauss | 136:2da626f30efa | 32 | return ( u_elapsed_time ); |
klauss | 136:2da626f30efa | 33 | } |
klauss | 136:2da626f30efa | 34 | |
klauss | 136:2da626f30efa | 35 | void elapsed_time_mean_start ( void ) |
klauss | 136:2da626f30efa | 36 | { |
klauss | 136:2da626f30efa | 37 | if ( boolInit_test_mean ) |
klauss | 136:2da626f30efa | 38 | { |
klauss | 136:2da626f30efa | 39 | u16Elapsed_time_count = u16_ELAPSED_TIME_COUNT_TIMES; |
klauss | 136:2da626f30efa | 40 | |
klauss | 136:2da626f30efa | 41 | u64Elapsed_time_u_sum = 0; |
klauss | 136:2da626f30efa | 42 | |
klauss | 136:2da626f30efa | 43 | boolInit_test_mean = false; |
klauss | 136:2da626f30efa | 44 | } |
klauss | 136:2da626f30efa | 45 | |
klauss | 136:2da626f30efa | 46 | elapsed_timer_mean.start (); |
klauss | 136:2da626f30efa | 47 | |
klauss | 136:2da626f30efa | 48 | elapsed_timer_mean.reset (); |
klauss | 136:2da626f30efa | 49 | } |
klauss | 136:2da626f30efa | 50 | |
klauss | 136:2da626f30efa | 51 | void elapsed_time_mean_end ( void ) |
klauss | 136:2da626f30efa | 52 | { |
klauss | 136:2da626f30efa | 53 | if ( u16Elapsed_time_count ) |
klauss | 136:2da626f30efa | 54 | { |
klauss | 136:2da626f30efa | 55 | u16Elapsed_time_count--; |
klauss | 136:2da626f30efa | 56 | |
klauss | 136:2da626f30efa | 57 | elapsed_timer_mean.stop (); |
klauss | 136:2da626f30efa | 58 | |
klauss | 136:2da626f30efa | 59 | u64Elapsed_time_u_sum += elapsed_timer_mean.read_us (); |
klauss | 136:2da626f30efa | 60 | |
klauss | 136:2da626f30efa | 61 | elapsed_timer_mean.start (); |
klauss | 136:2da626f30efa | 62 | elapsed_timer_mean.reset (); |
klauss | 136:2da626f30efa | 63 | |
klauss | 136:2da626f30efa | 64 | if ( u16Elapsed_time_count == 0 ) boolEnd_test_mean = true; |
klauss | 136:2da626f30efa | 65 | } |
klauss | 136:2da626f30efa | 66 | else if ( boolEnd_test_mean ) |
klauss | 136:2da626f30efa | 67 | { |
klauss | 136:2da626f30efa | 68 | vz_printf ( "Elapsed_time_mean : [ %.2lfu ]", double ( u64Elapsed_time_u_sum / u16_ELAPSED_TIME_COUNT_TIMES ) ); |
klauss | 136:2da626f30efa | 69 | |
klauss | 136:2da626f30efa | 70 | boolEnd_test_mean = false; |
klauss | 136:2da626f30efa | 71 | boolInit_test_mean = true; |
klauss | 136:2da626f30efa | 72 | |
klauss | 136:2da626f30efa | 73 | elapsed_timer_mean.stop (); |
klauss | 136:2da626f30efa | 74 | } |
klauss | 136:2da626f30efa | 75 | } |