|
Subject: [Source] Simple C/C++ Perfometer : Copying char[] to vector (Version CS-1.0) Newsgroups: gmane.comp.lang.c++.perfometer Date: 2004-07-14 12:29:11 GMT (4 years, 50 weeks, 6 days, 7 hours and 15 minutes ago) // ===================================== // C/C++ Program Performance Measurement // ------------------------------------- // Simple C/C++ Perfometer : Exception Handling // Version CS-1.0 // ------------------------------------- // FILE : cps_main.cpp // ------------------------------------- // Copyright (C) 2002-2004 Alex Vinokur // mailto:alexvn <at> connect.to // http://up.to/alexv // ===================================== // ============== #include "copystr.h" // -------------------------------------- static vector<string> foo_names; static vector<string>::iterator iter_names; static vector<vector<clock_t> > used_time; static ulong test_no = 0; static ulong file_size; static uint foo_setw = 0; // ------------ void measure (ulong no_of_repetitions) { clock_t start_time; clock_t end_time; vector<clock_t> elapsed_time_vect; data_init(); // ------------------------------- // cout << "\t---> Test-" << ++test_no << " started" << endl; cout << "."; cout.flush(); // ------------------------------- MEASURE_WITH_NO_ARG (func_memcpy); MEASURE_WITH_NO_ARG (func_copy); MEASURE_WITH_NO_ARG (func_copy_with_reserve); MEASURE_WITH_NO_ARG (func_transform); MEASURE_WITH_NO_ARG (func_ctor); // ------------------------------- // cerr << "\t Test-" << test_no << " finished" << endl; } // ------------ void show (ulong no_of_tests) { clock_t units; clock_t sum; #define THRESHOLD 0.2 const ulong threshold = ulong(no_of_tests * THRESHOLD); assert ((threshold * 2) <= no_of_tests); cout << endl; assert (foo_names.size() == used_time.size()); for (ulong i = 0; i < foo_names.size(); i++) { sum = 0; assert (no_of_tests == used_time[i].size()); for (ulong k = threshold; k < (used_time[i].size() - threshold); k++) { sum += used_time[i][k]; } units = sum/(used_time[i].size() - (threshold * 2)); cout << setw(foo_setw) << std::left << foo_names[i] << " : " << setw(6) << std::right << units << " units" << " ("; cout.setf(ios::fixed, ios::floatfield); cout << setprecision (3) << (float(units)/float(CLOCKS_PER_SEC)) << " secs)" << endl; } } // ------------ void run (ulong no_of_runs, ulong no_of_tests, ulong no_of_repetitions) { for (ulong i = 0; i < no_of_runs; i++) { test_no = 0; foo_names.clear(); used_time.clear(); // ---------------------- cout << endl << endl << " Run-" << (i + 1) << " of " << no_of_runs << " : Started "; cout.flush(); for (ulong k = 0; k < no_of_tests; k++) measure (no_of_repetitions); show (no_of_tests); cout << " Run-" << (i + 1) << " of " << no_of_runs << " : Finished"<< endl << endl; } } // ------------ int main(int argc, char** argv) { cout << endl; cout << string (string (PROGRAM_NAME).size(), '=') << endl; cout << PROGRAM_NAME << endl; cout << PROGRAM_VERSION << endl; cout << string (string (PROGRAM_NAME).size(), '=') << endl; // -------------------------- cout << endl; cout << endl; show_compiler_info(); cout << endl; cout << "\tYOUR COMMAND LINE : "; string exe_name (argv[0]); cout << exe_name.substr (exe_name.find_last_of ("/\\") + 1) << " "; for (long i = 1; i < argc; i++) cout << argv[i] << " "; cout << endl; cout << endl; if (!(argc >= 3)) { cout << "\tUSAGE : " << argv[0] << " " << "<No. of tests> <No. of repetitions> [<No. of runs>]" << endl; return 1; } assert (argc >= 3); const ulong no_of_tests = atoi (argv[1]); assert (no_of_tests > 0); const ulong no_of_repetitions = atoi (argv[2]); assert (no_of_repetitions > 0); const ulong no_of_runs = ((argc > 3) ? atoi (argv[3]) : 1); assert (no_of_runs > 0); cout << "\t### Number of runs : " << no_of_runs << endl; cout << "\t### Number of tests : " << no_of_tests << endl; cout << "\t### Number of repetitions : " << no_of_repetitions << endl; cout << "\t### CLOCKS_PER_SEC : " << CLOCKS_PER_SEC << endl; cout << endl; // ----------------------------- run (no_of_runs, no_of_tests, no_of_repetitions); return 0; } ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com |
|
|