1 /* performance_test.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * email: daniel.otte@rub.de
33 #include "string-extras.h"
34 #include "performance_test.h"
37 static volatile uint32_t ovfcounter;
39 static uint32_t const_overhead=0;
40 static uint32_t int_overhead=0;
42 void calibrateTimer(void){
46 const_overhead = (uint32_t)t;
50 gptm_set_timer_32periodic(PERF_TIMER);
53 void startTimer(uint8_t granularity){
54 gptm_stop_timer(PERF_TIMER, 0);
55 gptm_write_timer(PERF_TIMER, 0, 0);
57 gptm_set_timer_prescaler(PERF_TIMER, 0, granularity-1);
58 gptm_start_timer(PERF_TIMER, 0);
60 gptm_set_timer_prescaler(PERF_TIMER, 0, 0);
64 uint64_t stopTimer(void){
65 gptm_stop_timer(PERF_TIMER, 0);
67 ret = gptm_read_timer(PERF_TIMER, 0);
68 ret -= const_overhead;
69 ret -= ovfcounter * int_overhead;
73 void getOverhead(uint32_t* constoh, uint32_t* intoh){
74 *constoh = const_overhead;
75 *intoh = int_overhead;
78 void print_time(const char* s, uint64_t t){
84 for(c=strlen(sv); c<11; ++c){
90 void print_overhead(void){
92 cli_putstr("\r\n\r\n=== benchmark ===");
93 ultoa(const_overhead, str, 10);
94 cli_putstr("\r\n\tconst overhead: ");
96 ultoa(int_overhead, str, 10);
97 cli_putstr("\r\n\tinterrupt overhead: ");