X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=test_src%2Fperformance_test.c;h=20b616f1edc99f249a0d782048fb7f6697d5ac93;hp=ad745fc4c96a0b6480bb25fb563500f911040689;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=52ec168ece9d61bd9cb652235dfe8faee6232a11 diff --git a/test_src/performance_test.c b/test_src/performance_test.c index ad745fc..20b616f 100644 --- a/test_src/performance_test.c +++ b/test_src/performance_test.c @@ -1,7 +1,7 @@ /* performance_test.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,12 +18,12 @@ */ /* * author: Daniel Otte - * email: daniel.otte@rub.de + * email: bg@nerilex.org * license: GPLv3 - * - * + * + * **/ - + #include "config.h" #include #include @@ -31,7 +31,7 @@ #include #include #include -#include "cli.h" +#include #include "performance_test.h" @@ -41,23 +41,22 @@ -uint32_t ovfcounter; +static volatile uint32_t ovfcounter; -uint16_t const_overhead=0; -uint16_t int_overhead=0; +static uint16_t const_overhead = 0; +static uint16_t int_overhead = 0; ISR(TIMER1_OVF_vect){ - ovfcounter++; + ++ovfcounter; } void calibrateTimer(void){ - volatile uint8_t i; startTimer(1); stopTimer(); const_overhead = TCNT1; startTimer(1); - TCNT1=0xFFFE; - i++; + TCNT1 = 0xFFFE; + asm("nop"); stopTimer(); int_overhead = TCNT1; } @@ -67,46 +66,30 @@ void startTimer(uint8_t granularity){ TCNT1 = 0; ovfcounter = 0; TCCR1A = 0x00; - TIMSK &= 0xC3; - TIMSK |= _BV(TOIE1); /* enable TOIE1 */ + TIMSK = _BV(TOIE1); /* enable TOIE1 */ TCCR1B = granularity & 0x7; /* start timer */ } uint64_t stopTimer(void){ TCCR1B = 0; /* stop timer */ uint64_t ret; - ret = (ovfcounter<<16) | TCNT1; + ret = (((uint64_t)ovfcounter)<<16) | TCNT1; ret -= const_overhead; ret -= ovfcounter * int_overhead; return ret; } -void getOverhead(uint16_t* constoh, uint16_t* intoh){ +void getOverhead(uint16_t *constoh, uint16_t *intoh){ *constoh = const_overhead; - *intoh = int_overhead; + *intoh = int_overhead; } -void print_time_P(PGM_P s, uint64_t t){ - char sv[16]; - uint8_t c; - cli_putstr_P(PSTR("\r\n")); - cli_putstr_P(s); - ultoa((unsigned long)t, sv, 10); - for(c=strlen(sv); c<11; ++c){ - cli_putc(' '); - } - cli_putstr(sv); +void print_time_P(PGM_P s, uint32_t t){ + printf_P(PSTR("%S%11"PRIu32), t); } void print_overhead(void){ - char str[16]; - cli_putstr_P(PSTR("\r\n\r\n=== benchmark ===")); - utoa(const_overhead, str, 10); - cli_putstr_P(PSTR("\r\n\tconst overhead: ")); - cli_putstr(str); - utoa(int_overhead, str, 10); - cli_putstr_P(PSTR("\r\n\tinterrupt overhead: ")); - cli_putstr(str); + printf_P(PSTR("\n=== benchmark ===\n\tconst overhead: %7"PRIu16"\n\tinterrupt overhead: %7"PRIu16"\n"), const_overhead, int_overhead); }