auto TestComparativeSortingInternal(const std::vector<TElem> &data, TInvoker func) { // verify the algorithm auto sample = data; auto cmp = std::less<TElem>(); auto track = func(sample.begin(), sample.end(), cmp); if (!std::is_sorted(sample.begin(), sample.end(), cmp)) { throw std::runtime_error("algorithm not working"); } // evaluate the algorithm using clock = std::chrono::high_resolution_clock; std::vector<std::vector<TElem>> testbench(TestRepetition, data); auto first_tick = clock::now(); for (size_t i = 0; i < TestRepetition; ++i) { auto &target = testbench[i]; func(std::begin(target), std::end(target), cmp); } auto last_tick = clock::now(); microseconds_t dur = std::chrono::duration_cast<microseconds_t>(last_tick - first_tick) / TestRepetition; return std::make_pair(track, dur); }
// Main Verification Function CCS_MAIN(int argc, char *argv[]) { // teste your design // blur filter cout << "*** start testbench *** " << endl; testbench(); cout << "*** end of testbench *** " << endl; // test your algorithm in sw // grayscale convertion cout << "*** start sw test *** " << endl; sw_test(); cout << "*** end of sw test *** " << endl; // Free the memory delete [] red_in; delete [] green_in; delete [] blue_in; CCS_RETURN(0); }
auto TestRadixSortingInternal(const std::vector<TElem> &data) { // verify the algorithm auto sample = data; RadixSort(sample.begin(), sample.end()); if (!std::is_sorted(sample.begin(), sample.end(), std::less<TElem>())) { throw std::runtime_error("algorithm not working"); } // evaluate the algorithm using clock = std::chrono::high_resolution_clock; std::vector<std::vector<TElem>> testbench(TestRepetition, data); auto first_tick = clock::now(); for (size_t i = 0; i < TestRepetition; ++i) { auto &target = testbench[i]; RadixSort(std::begin(target), std::end(target)); } auto last_tick = clock::now(); return std::chrono::duration_cast<microseconds_t>(last_tick - first_tick) / TestRepetition; }
/* MAIN */ int main() { testbench(); return 1; };