#include #include #include #include using namespace std; /*Modifiable test params*/ const int IMG_W = 1920; const int IMG_H = 1080; const int N_OPERATIONS = 80; const int OPS_COMPLEXITY = 1; /* */ const int N_CHANNELS = 4; const int N_ELEMS = IMG_W * IMG_H; const int BUFFER_SIZE = N_ELEMS * N_CHANNELS; clock_t start_ticks; void execTree(bool recycle); void execOp(float* out_buffer); void startBenchmark(string title); void endBenchmark(); int main() { startBenchmark("Without recycling: "); execTree(false); endBenchmark(); startBenchmark("With recycling: "); execTree(true); endBenchmark(); } void execTree(bool recycle) { float* out_buffer = nullptr; for (int i = 0; i < N_OPERATIONS;i++) { if (!out_buffer) { out_buffer = (float*)malloc(BUFFER_SIZE * sizeof(float)); } execOp(out_buffer); if (!recycle) { free(out_buffer); out_buffer = nullptr; } } } void execOp(float* out_buffer) { for (int offset = 0; offset < BUFFER_SIZE;offset += N_CHANNELS) { for (int ch_idx = 0; ch_idx < N_CHANNELS; ch_idx++) { for (int complex = 0; complex < OPS_COMPLEXITY; complex++) { //dummy gamma operation float dummy_color_input = out_buffer[offset + ch_idx]; float dummy_gamma_input = 2.5; out_buffer[offset + ch_idx] = dummy_color_input > 0.0f ? powf(dummy_color_input, dummy_gamma_input) : dummy_color_input; } } } } void startBenchmark(string title) { std::cout << title + "\n"; start_ticks = clock(); } void endBenchmark() { clock_t end_ticks = clock();; float secs = (end_ticks - start_ticks) / (float)CLOCKS_PER_SEC; printf("\nExecution time: %f seconds\n\n", secs); }