-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/benchmarks: add dynamic memory allocation measurement
add a test into latency_measure test case to measure the average time for dynamic memory allocation and release. Signed-off-by: Chen Peng1 <[email protected]>
- Loading branch information
Showing
4 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2021 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr.h> | ||
#include <timing/timing.h> | ||
#include "utils.h" | ||
|
||
#define TEST_COUNT 100 | ||
#define TEST_SIZE 10 | ||
|
||
void heap_malloc_free(void) | ||
{ | ||
timing_t heap_malloc_start_time = 0U; | ||
timing_t heap_malloc_end_time = 0U; | ||
|
||
timing_t heap_free_start_time = 0U; | ||
timing_t heap_free_end_time = 0U; | ||
|
||
uint32_t count = 0U; | ||
uint32_t sum_malloc = 0U; | ||
uint32_t sum_free = 0U; | ||
|
||
timing_start(); | ||
|
||
while (count != TEST_COUNT) { | ||
heap_malloc_start_time = timing_counter_get(); | ||
void *allocated_mem = k_malloc(TEST_SIZE); | ||
|
||
heap_malloc_end_time = timing_counter_get(); | ||
if (allocated_mem == NULL) { | ||
printk("Failed to alloc memory from heap " | ||
"at count %d\n", count); | ||
break; | ||
} | ||
|
||
heap_free_start_time = timing_counter_get(); | ||
k_free(allocated_mem); | ||
heap_free_end_time = timing_counter_get(); | ||
|
||
sum_malloc += timing_cycles_get(&heap_malloc_start_time, | ||
&heap_malloc_end_time); | ||
sum_free += timing_cycles_get(&heap_free_start_time, | ||
&heap_free_end_time); | ||
count++; | ||
} | ||
|
||
PRINT_STATS_AVG("Average time for heap malloc", sum_malloc, count); | ||
PRINT_STATS_AVG("Average time for heap free", sum_free, count); | ||
|
||
timing_stop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters