Skip to content

Commit

Permalink
Add performance measurements to mbedtls tests (Mbed-TLS#6)
Browse files Browse the repository at this point in the history
Also add get timer in [uS] to timing library
  • Loading branch information
dvir2000 authored and NirEkhauz committed Dec 28, 2017
1 parent 4b660ec commit d525688
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/mbedtls/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ extern volatile int mbedtls_timing_alarmed;
*/
unsigned long mbedtls_timing_hardclock( void );

/**
* \brief Return the elapsed time in micro seconds
*
* \param val points to a timer structure
* \param reset if set to 1, the timer is restarted
*/

unsigned long long mbedtls_timing_get_timer_us( struct mbedtls_timing_hr_time *val, int reset );


/**
* \brief Return the elapsed time in milliseconds
*
Expand All @@ -88,6 +98,7 @@ unsigned long mbedtls_timing_hardclock( void );
* get_timer(0) }` the value time1+time2 is only approximately
* the delay since the first reset.
*/

unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );

/**
Expand Down
21 changes: 21 additions & 0 deletions library/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,27 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int
}
}

unsigned long long mbedtls_timing_get_timer_us( struct mbedtls_timing_hr_time *val, int reset )
{
unsigned long long delta;
struct timeval offset;
struct _hr_time *t = (struct _hr_time *) val;

gettimeofday( &offset, NULL );

if( reset )
{
t->start.tv_sec = offset.tv_sec;
t->start.tv_usec = offset.tv_usec;
return( 0 );
}

delta = ( offset.tv_sec - t->start.tv_sec ) * 1000 * 1000
+ ( offset.tv_usec - t->start.tv_usec ) ;

return( delta );
}

static void sighandler( int signum )
{
mbedtls_timing_alarmed = 1;
Expand Down

0 comments on commit d525688

Please sign in to comment.