Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ARRAY_SIZE 256
- volatile uint32_t time_unsorted;
- volatile uint32_t time_sorted;
- volatile uint32_t start_time, end_time;
- volatile uint16_t sorted_array[ARRAY_SIZE];
- volatile uint16_t unsorted_array[ARRAY_SIZE];
- volatile uint32_t cnt_tick;
- volatile uint32_t dummy = 0; // Переменная для предотвращения оптимизации
- void SysTick_Init(void){
- SysTick->SR = 0;
- SysTick->CNT = 0;
- SysTick->CTLR = 5;
- }
- static uint32_t random_seed = 123456789;
- uint32_t rand_xorshift() {
- random_seed ^= random_seed << 13;
- random_seed ^= random_seed >> 17;
- random_seed ^= random_seed << 5;
- return random_seed;
- }
- uint32_t measure_time(volatile uint16_t *array) {
- start_time = SysTick->CNT;
- for (uint32_t i = 0; i < ARRAY_SIZE; i++) {
- //if (array[i] > ARRAY_SIZE/2) { // 0x2512 - время
- if (array[i] > 2 ) { // 0x260f - время
- //if (array[i] > ARRAY_SIZE-2){ // 0x2416 - время "Always Not Taken" !!!!!
- //"Always Not Taken" можно перевести на русский как "Всегда не выполняется"
- dummy++;
- } else {
- dummy--;
- }
- }
- end_time = SysTick->CNT;
- return end_time - start_time;
- }
- int main() {
- SysTick_Init();
- for (uint32_t i = 0; i < ARRAY_SIZE; i++) {
- sorted_array[i] = i;
- unsorted_array[i] = (uint16_t)rand_xorshift();
- }
- while (1){
- time_sorted = measure_time(sorted_array);
- time_unsorted = measure_time(unsorted_array);
- cnt_tick = SysTick->CNT;
- asm("nop");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement