|
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:26:04 GMT (4 years, 50 weeks, 6 days, 7 hours and 10 minutes ago) // ===================================== // C/C++ Program Performance Measurement // ------------------------------------- // Simple C/C++ Perfometer : Exception Handling // Version CS-1.0 // ------------------------------------- // FILE : cps_test.cpp // ------------------------------------- // Copyright (C) 2002-2004 Alex Vinokur // mailto:alexvn <at> connect.to // http://up.to/alexv // ===================================== // ============== #include "copystr.h" #define STR_LEN 100 // --------------- char cstr[STR_LEN]; struct char_identity { char operator()(char ch) const { return ch; } }; // --------------- // --------------- void data_init() { #define for (uint i = 0; i < STR_LEN; i++) cstr[i] = i; } // ----------------------- void func_memcpy() { vector<char> vect (STR_LEN); memcpy(&vect[0], cstr, STR_LEN); } void func_copy() { vector<char> vect; copy(cstr, cstr + STR_LEN, back_inserter(vect)); } void func_copy_with_reserve() { vector<char> vect; vect.reserve(STR_LEN); copy(cstr, cstr + STR_LEN, back_inserter(vect)); } void func_transform() { vector<char> vect (STR_LEN); transform(cstr, cstr + STR_LEN, vect.begin(), char_identity()); } void func_ctor() { vector<char> vect (cstr, cstr + STR_LEN); } ------------------------------------------------------- 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 |
|
|