|
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:12:02 GMT (4 years, 50 weeks, 6 days, 7 hours and 19 minutes ago) // ===================================== // C/C++ Program Performance Measurement // ------------------------------------- #define PROGRAM_NAME "Simple C/C++ Perfometer : Copying String" #define PROGRAM_VERSION "Version CS-1.0" // ------------------------------------- // FILE : copystr.h // ------------------------------------- // Copyright (C) 2002-2004 Alex Vinokur // mailto:alexvn <at> connect.to // http://up.to/alexv // ===================================== // ============== #include <ctime> #include <cassert> #include <string> #include <vector> #include <iostream> #include <iomanip> #include <sstream> #include <algorithm> using namespace std; // -------------------------------------- typedef unsigned long ulong; typedef unsigned int uint; // ====== Macros ====== #define MAX_VALUE(x,y) ((x) > (y) ? (x) : (y)) // --------------------- #define MEASURE_IT(x, y) \ foo_setw = MAX_VALUE (foo_setw, string (#y).size()); \ start_time = clock(); \ assert (start_time != clock_t (-1)); \ { for (ulong k = 0; k < no_of_repetitions; k++) { x; } } \ end_time = clock(); \ assert (end_time != clock_t (-1)); \ if (!(end_time > start_time)) { cout << "Number of repetitions is too small" << endl << "Good Luck" << endl << endl; exit(1); }\ assert (end_time > start_time); \ if (find (foo_names.begin(), foo_names.end(), #y) == foo_names.end()) \ { \ foo_names.push_back (#y); \ used_time.push_back (vector<clock_t>()); \ } \ assert (foo_names.size() == used_time.size()); \ iter_names = find (foo_names.begin(), foo_names.end(), #y); \ assert (iter_names != foo_names.end()); \ used_time[distance (foo_names.begin(), iter_names)].push_back ((end_time - start_time)) #define MEASURE_WITH_ARG(foo, argument) MEASURE_IT (foo(argument), foo) #define MEASURE_WITH_NO_ARG(foo) MEASURE_IT (foo(), foo) // ====== Function declaration ====== // ------ Info function ------ void show_compiler_info(void); // ------ Tested function ------ void data_init(void); void func_memcpy(void); void func_copy(void); void func_copy_with_reserve(void); void func_transform(void); void func_ctor(void); ------------------------------------------------------- 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 |
|
|