C/C++ Program Perfometer

32 views
Skip to first unread message

Alex Vinokur

unread,
Mar 5, 2002, 9:01:00 AM3/5/02
to

A program that enables
to get C/C++ program performance for any metrics
has been written.

|-----------------------------------------------|
|---> 1. Fragments from README.txt file etc <---|
|-----------------------------------------------|


============================================
--------- C/C++ Program Perfometer ---------
============================================

=====================================
AVAILABILITY

-----------------------------------
### Web page ###
http://alexvn.freeservers.com/s1/perfometer.html

Content.
1. Algorithm
2. Classes
3. Program Files
4. Compiling
5. Running (Log Files)
6. Download

-----------------------------------
### Download ###
http://alexvn.freeservers.com/s1/perfometer.zip

Also :
### Sources (in alt.sources) ###
http://groups.google.com/groups?hl=en&th=12f55903796dc3fa


Files:
0. README.txt
--- Program Files ---

1. macro.h Various Macro
2. common.h Common Function etc
3. user.h User-Specialized Function Declaration
4. pfmeter.h Definition of Common Classes
5. pfmeter2.h Implementation of Common Template Classes
6. pfmeter.c Implementation of Common (Non-Template) Classes
7. adapt.h Definition of User-Related Classes
8. adapt.c Implementation of User-Related Classes
9. demo.h Declaration of Measured/Compared Functions
10. demo.c Implementation of Measured/Compared functions
11. demo2.c Implementation of Measured/Compared functions
12. main.c Main Program

--- Log Files ---
16. log1_h.txt Running results (invocation : a.exe -h)
17. log2_s.txt Running results (invocation : a.exe -s)
18. log3_d.txt Running results (invocation : a.exe -d)
19. log4_m.txt Running results (invocation : a.exe -m)
20. log5.txt Running results (invocation : a.exe)
21. log6_v.txt Running results (invocation : a.exe -i 70000 -f 0.23 -e 11
-p 2500)

--- Info File ---
22. perfometer.html


=====================================
ENVIRONMENT

### System & Compiler ###

Windows98
gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp)
compiled by GNU C version 2.95.3 20010315/djgpp (release).


|-----------------------------------------------|
|-------------> 2. Sample Output <--------------|
|-----------------------------------------------|


#=========================
# C/C++ Program Perfometer
# Alex Vinokur
# http://up.to/alexvn
#-------------------------
# START
# Mon Mar 4 14:22:14 2002
#=========================

---> YOUR COMMAND LINE : a.exe -m


======================================================================
* ENVIRONMENT VARIABLES (Actual Values)
* -------------------------------------
* Measurement Report : Disable
* Tracing Report : Disable
* Total Iteration : 90000
* Total Tests : 15
* Scale per Calls Value : 10000
* Confidence Threshold : 0.17
======================================================================

==========================================
%%========================================
%%
%% Total Measured Resources : 3
%%
%% ---------- Resource#1 ----------
%% Resource Name : user time used
%% Resource Cost Unit : uclock
%% Resource State Unit : uclock
%% ---> Total measured functions : 19
%%
%% ---------- Resource#2 ----------
%% Resource Name : user time used (via rusage)
%% Resource Cost Unit : msec
%% Resource State Unit : timeval
%% ---> Total measured functions : 2
%%
%% ---------- Resource#3 ----------
%% Resource Name : pseudo resource
%% Resource Cost Unit : cost-BBB-unit
%% Resource State Unit : state-AAA-unit
%% ---> Total measured functions : 2
%%
%%
%%========================================
==========================================


||||||||||||||||||||||||||||||||||||||||
||
|| ---------------
|| Resource#1 of 3
|| ---------------
|| Resource Name : user time used
|| Resource Cost Unit : uclock
|| Resource State Unit : uclock
|| ---------------
||
|| ******************************
|| *** Performance Comparison ***
|| ******************************
||
||
||||||||||||||||||||||||||||||||||||||||

#================================================
# Comparison Group#1 of 4 : delete-new-string etc
#------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#================================================
:
----------------------------------------------------------------------------------------

: demo_01 : demo.c #98 : do
nothing -> 87
: demo_02 : demo.c #108 : delete new string of size
40 -> 16407
: demo_03 : demo.c #118 : delete new string of size
4 -> 12482
: demo_04 : demo.c #128 : delete new string of size 4 (10
times) -> 127645
: demo_05 : demo.c #141 : delete new string of size 4 (20
times) -> 259604
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#2 of 4 : delete-new-string only
#-------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#=================================================
:
----------------------------------------------------------------------------------------

: demo_05 : demo.c #141 : delete new string of size 4 (20
times) -> 259604
: demo_06 : demo.c #155 : delete new string of size
6 -> 14638
: demo_07 : demo.c #183 : delete new string of size
9 -> 14117
:
----------------------------------------------------------------------------------------

#=======================================================
# Comparison Group#3 of 4 : ostrstream vs. ostringstream
#-------------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#=======================================================
:
----------------------------------------------------------------------------------------

: write_to_stream : demo2.c #142 :
to-ostringstream-5 -> 106443
: write_to_stream : demo2.c #152 :
to-ostringstream-25 -> 462756
: write_to_stream : demo2.c #162 :
to-ostrstream5 -> 36716
: write_to_stream : demo2.c #172 :
to-ostrstream25 -> 41662
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#4 of 4 : strlen vs. string-size
#-------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#=================================================
:
----------------------------------------------------------------------------------------

: get_string_size : demo2.c #75 :
string-size-5 -> 307
: get_string_size : demo2.c #84 :
string-size-25 -> 309
: get_string_size : demo2.c #93 :
string-size-125 -> 310
: get_string_size : demo2.c #101 :
strlen-5 -> 598
: get_string_size : demo2.c #109 :
strlen-25 -> 1790
: get_string_size : demo2.c #117 :
strlen-125 -> 9512
:
----------------------------------------------------------------------------------------


||||||||||||||||||||||||||||||||||||||||
||
|| ---------------
|| Resource#2 of 3
|| ---------------
|| Resource Name : user time used (via rusage)
|| Resource Cost Unit : msec
|| Resource State Unit : timeval
|| ---------------
||
|| ******************************
|| *** Performance Comparison ***
|| ******************************
||
||
||||||||||||||||||||||||||||||||||||||||

#================================================
# Comparison Group#1 of 4 : delete-new-string etc
#------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : msec
# Resource State Unit : timeval
#================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#2 of 4 : delete-new-string only
#-------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : msec
# Resource State Unit : timeval
#=================================================
:
----------------------------------------------------------------------------------------

: demo_06 : demo.c #162 : delete new string of size
6 -> 10
: demo_08 : demo.c #196 : delete new string of size
6 -> 13.8788
:
----------------------------------------------------------------------------------------

#=======================================================
# Comparison Group#3 of 4 : ostrstream vs. ostringstream
#-------------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : msec
# Resource State Unit : timeval
#=======================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#4 of 4 : strlen vs. string-size
#-------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : msec
# Resource State Unit : timeval
#=================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------


||||||||||||||||||||||||||||||||||||||||
||
|| ---------------
|| Resource#3 of 3
|| ---------------
|| Resource Name : pseudo resource
|| Resource Cost Unit : cost-BBB-unit
|| Resource State Unit : state-AAA-unit
|| ---------------
||
|| ******************************
|| *** Performance Comparison ***
|| ******************************
||
||
||||||||||||||||||||||||||||||||||||||||

#================================================
# Comparison Group#1 of 4 : delete-new-string etc
#------------------------------------------------
# Resource Name : pseudo resource
# Resource Cost Unit : cost-BBB-unit
# Resource State Unit : state-AAA-unit
#================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#2 of 4 : delete-new-string only
#-------------------------------------------------
# Resource Name : pseudo resource
# Resource Cost Unit : cost-BBB-unit
# Resource State Unit : state-AAA-unit
#=================================================
:
----------------------------------------------------------------------------------------

: demo_06 : demo.c #170 : delete new string of size
6 -> BBB-174005461
: demo_09 : demo.c #208 : delete new string of size
6 -> BBB-82659391
:
----------------------------------------------------------------------------------------

#=======================================================
# Comparison Group#3 of 4 : ostrstream vs. ostringstream
#-------------------------------------------------------
# Resource Name : pseudo resource
# Resource Cost Unit : cost-BBB-unit
# Resource State Unit : state-AAA-unit
#=======================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------

#=================================================
# Comparison Group#4 of 4 : strlen vs. string-size
#-------------------------------------------------
# Resource Name : pseudo resource
# Resource Cost Unit : cost-BBB-unit
# Resource State Unit : state-AAA-unit
#=================================================
:
----------------------------------------------------------------------------------------

: No functions to be compared
:
----------------------------------------------------------------------------------------


#=========================
# C/C++ Program Perfometer
# Alex Vinokur
# http://up.to/alexvn
#-------------------------
# FINISH
# Mon Mar 4 14:24:43 2002
#=========================


|-----------------------------------------------|
|-> 3. Sample Code (related to Sample Output) <-|
|-----------------------------------------------|


// #########################################################
// === File #9 of 12 : demo.h ==============================
// ------------------- C++ code : BEGIN --------------------

// ==============================================================
//
// Copyright (c) 2002 by Alex Vinokur. This work and all works
// derived from it may be copied and modified without any
// restrictions other than that a copy of this copyright notice
// must be included in any copy of this work or any derived work.
//
// ==============================================================
// #########################################################
// ## mailto:ale...@bigfoot.com, mailto:al...@hitechclub.com
// ## http://up.to/alexv, http://go.to/alexv_math
// #########################################################
// ==============================================================


// ##############################################################
//
// SOFTWARE : C/C++ Program Perfometer
// FILE : demo.h
//
// DESCRIPTION :
// Declaration of measured/compared functions
//
// ---- ----------
// Created 2002-03-04
// ---- ----------
//
// ##############################################################

///////////////
#ifndef _DEMO_H
#define _DEMO_H
///////////////

// ===========================
#include "adapt.h"

// ---------------------------
void demo_01 (void);
void demo_02 (void);
void demo_03 (void);
void demo_04 (void);
void demo_05 (void);
void demo_06 (void);
void demo_07 (void);
void demo_08 (void);
void demo_09 (void);
void demo_10 (void);
void demo_11 (void);

void get_string_size (void);
void write_to_stream (void);

// ###########################################
#endif
// ###########################################

// ------------------- C++ code : END ----------------------
// === File #9 of 12 : demo.h ==============================


// #########################################################
// === File #10 of 12 : demo.c =============================
// ------------------- C++ code : BEGIN --------------------

// ==============================================================
//
// Copyright (c) 2002 by Alex Vinokur. This work and all works
// derived from it may be copied and modified without any
// restrictions other than that a copy of this copyright notice
// must be included in any copy of this work or any derived work.
//
// ==============================================================
// #########################################################
// ## mailto:ale...@bigfoot.com, mailto:al...@hitechclub.com
// ## http://up.to/alexv, http://go.to/alexv_math
// #########################################################
// ==============================================================


// ##############################################################
//
// SOFTWARE : C/C++ Program Perfometer
// FILE : demo.c
//
// DESCRIPTION :
// Implementation of measured/compared functions
//
// ---- ----------
// Created 2002-03-04
// ---- ----------
//
// ##############################################################


// ==============
#include "demo.h"
// ==============


// #########################################
// #
// # Function Implementation
// # Prototypes are in file user.h
// #
// #########################################
// =============================
void SetEnvIt ()
{
SetTotalTests (15);
SetScaleAndTotalIterations (10000, 90000);
SetDiscardingThreshold(0.17);

SetDetailedMeasurementReportFlag(true);
SetMeasurementReportFlag(true);
//SetTracingReportFlag(true);
}


// =============================
void MeasureIt ()
{
MeasureFunc (demo_10);
MeasureFunc (demo_11);
}

// =============================
void CompareIt ()
{
CompareFunc ("delete-new-string etc", demo_01);
CompareFunc ("delete-new-string etc", demo_02);
CompareFunc ("delete-new-string etc", demo_03);
CompareFunc ("delete-new-string etc", demo_04);
CompareFunc ("delete-new-string etc", demo_05);

CompareFunc ("delete-new-string only", demo_05);
CompareFunc ("delete-new-string only", demo_06);
CompareFunc ("delete-new-string only", demo_07);
CompareFunc ("delete-new-string only", demo_08);
CompareFunc ("delete-new-string only", demo_09);

CompareFunc ("strlen vs. string-size", get_string_size);

CompareFunc ("ostrstream vs. ostringstream", write_to_stream);

} // CompareIt

// #########################################
// #
// # Functions To Be Measured (Compared)
// # Prototypes are in file demo.h
// #
// #########################################
// =============================
void demo_01 (void)
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "do nothing")
{
}
} // demo_01


// =============================
void demo_02 (void)
{

TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 40")
{
delete new std::string("1234567890123456789012345678901234567890");
}
} // demo_02


// =============================
void demo_03 (void)
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 4")
{
delete new std::string("ABCD");
}
} // demo_03


// =============================
void demo_04 (void)
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 4 (10 times)")
{
for (int i = 0; i < 10; i++)
{
delete new std::string("ABCD");
}
}
} // demo_04


// =============================
void demo_05 (void)
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 4 (20 times)")
{
for (int i = 0; i < 20; i++)
{
delete new std::string("ABCD");
}
}
} // demo_05


// =============================
void demo_06 (void)
{
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 6")
{
delete new std::string("ABCDEF");
}
}

{
TURN_ON (timeval, double, RESOURCE_user_time_used, "delete new string of
size 6")
{
delete new std::string("ABCDEF");
}
}


{
TURN_ON (AAA, BBB, RESOURCE_pseudo, "delete new string of size 6")
{
delete new std::string("ABCDEF");
}
}

} // demo_06


// =============================
void demo_07 (void)
{
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 9")
{
delete new std::string("ABCDEF123");
}
}

} // demo_07


// =============================
void demo_08 (void)
{
{
TURN_ON (timeval, double, RESOURCE_user_time_used, "delete new string of
size 6")
{
delete new std::string("ABCDEF123");
}
}

} // demo_08

// =============================
void demo_09 (void)
{
{
TURN_ON (AAA, BBB, RESOURCE_pseudo, "delete new string of size 6")
{
delete new std::string("ABCDEF123");
}
}

} // demo_09

// =============================
void demo_10 (void)
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "delete new string
of size 5")
{
delete new std::string("ABCDE");
}
} // demo_10


// =============================
void demo_11 (void)
{
char str[] = "ABCD";
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, "strlen-4")
{
strlen(str);
}
} // demo_11

// ###########################################

// ------------------- C++ code : END ----------------------
// === File #10 of 12 : demo.c =============================

// #########################################################
// === File #11 of 12 : demo2.c ============================
// ------------------- C++ code : BEGIN --------------------

// ==============================================================
//
// Copyright (c) 2002 by Alex Vinokur. This work and all works
// derived from it may be copied and modified without any
// restrictions other than that a copy of this copyright notice
// must be included in any copy of this work or any derived work.
//
// ==============================================================
// #########################################################
// ## mailto:ale...@bigfoot.com, mailto:al...@hitechclub.com
// ## http://up.to/alexv, http://go.to/alexv_math
// #########################################################
// ==============================================================


// ##############################################################
//
// SOFTWARE : C/C++ Program Perfometer
// FILE : demo2.c
//
// DESCRIPTION :
// Implementation of measured/compared functions
//
// ---- ----------
// Created 2002-03-04
// ---- ----------
//
// ##############################################################

// ==============
#include "demo.h"
// ==============

// #########################################
// #
// # Functions To Be Measured (Compared)
// # Prototypes are in file demo.h
// #
// #########################################

#define STRING_SIZE_1 5
#define STRING_SIZE_2 25
#define STRING_SIZE_3 125

// ----------------------------
void get_string_size (void)
{
string sstr1 (STRING_SIZE_1, 'a');
string sstr2 (STRING_SIZE_2, 'b');
string sstr3 (STRING_SIZE_3, 'c');

char cstr1 [STRING_SIZE_1 + 1];
char cstr2 [STRING_SIZE_2 + 1];
char cstr3 [STRING_SIZE_3 + 1];

strcpy (cstr1, sstr1.c_str());
strcpy (cstr2, sstr2.c_str());
strcpy (cstr3, sstr3.c_str());

const string text_sstr1 = "string-size-" + to_string (STRING_SIZE_1);
const string text_sstr2 = "string-size-" + to_string (STRING_SIZE_2);
const string text_sstr3 = "string-size-" + to_string (STRING_SIZE_3);

const string text_cstr1 = "strlen-" + to_string (STRING_SIZE_1);
const string text_cstr2 = "strlen-" + to_string (STRING_SIZE_2);
const string text_cstr3 = "strlen-" + to_string (STRING_SIZE_3);


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_sstr1)
{
sstr1.size();
}
}


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_sstr2)
{
sstr2.size();
}
}


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_sstr3)
{
sstr3.size();
}
}

// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_cstr1)
{
strlen (cstr1);
}
}

// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_cstr2)
{
strlen (cstr2);
}
}

// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_cstr3)
{
strlen (cstr3);
}
}

} // get_strlen

// ----------------------------
void write_to_stream (void)
{
string sstr1 (STRING_SIZE_1, 'a');
string sstr2 (STRING_SIZE_2, 'b');

const string text_osstr1 = "to-ostringstream-" + to_string (STRING_SIZE_1);
const string text_osstr2 = "to-ostringstream-" + to_string (STRING_SIZE_2);

const string text_ostr1 = "to-ostrstream" + to_string (STRING_SIZE_1);
const string text_ostr2 = "to-ostrstream" + to_string (STRING_SIZE_2);


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_osstr1)
{
ostringstream osstr;
osstr << sstr1;
}
}


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_osstr2)
{
ostringstream osstr;
osstr << sstr2;
}
}


// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_ostr1)
{
ostrstream ostr;
ostr << sstr1;
ostr.rdbuf()->freeze (0);
}
}

// ---------------------------------------------------------
{
TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, text_ostr2)
{
ostrstream ostr;
ostr << sstr2;
ostr.rdbuf()->freeze (0);
}
}

} // write_to_stream

// ------------------- C++ code : END ----------------------
// === File #11 of 12 : demo2.c ============================


--
===========================
Alex Vinokur
mailto:ale...@bigfoot.com
mailto:ale...@yahoo.com
http://up.to/alexvn
http://go.to/alexv_math
===========================


Alex Vinokur

unread,
Mar 11, 2002, 2:49:50 AM3/11/02
to
Performance of accesses to elements
in C-array,
STL vector,
STL basic_string
was measured when using
C/C++ Program Perfometer at
http://groups.google.com/groups?selm=3C84CF9B.AA99EFA8%40bigfoot.com .

===============================================================


gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp)
compiled by GNU C version 2.95.3 20010315/djgpp (release).
---------

Windows98
===============================================================

--- No optimization ---
#==========================================================
# Comparison Group#1 of 1 : access to array, vector, string
#----------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#==========================================================
: -------------------------------------------------------------------
: f1 : demo2.c #50 : operator[] - int array[100] -> 109
: f1 : demo2.c #63 : operator[] - int array[1000] -> 109
: f1 : demo2.c #77 : operator[] - int vector[100] -> 694
: f1 : demo2.c #91 : operator[] - int vector[1000] -> 710
: f1 : demo2.c #105 : operator[] - int string[100] -> 2959
: f1 : demo2.c #119 : operator[] - int string[1000] -> 2970
: f1 : demo2.c #133 : method at() - int string[100] -> 3865
: f1 : demo2.c #147 : method at() - int string[1000] -> 3866
: -------------------------------------------------------------------

--- Optimization O1 ---
#==========================================================
# Comparison Group#1 of 1 : access to array, vector, string
#----------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#==========================================================
: -------------------------------------------------------------------
: f1 : demo2.c #50 : operator[] - int array[100] -> 44
: f1 : demo2.c #63 : operator[] - int array[1000] -> 44
: f1 : demo2.c #77 : operator[] - int vector[100] -> 44
: f1 : demo2.c #91 : operator[] - int vector[1000] -> 44
: f1 : demo2.c #105 : operator[] - int string[100] -> 131
: f1 : demo2.c #119 : operator[] - int string[1000] -> 131
: f1 : demo2.c #133 : method at() - int string[100] -> 174
: f1 : demo2.c #147 : method at() - int string[1000] -> 174
: -------------------------------------------------------------------

--- Optimization O2 ---
#==========================================================
# Comparison Group#1 of 1 : access to array, vector, string
#----------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#==========================================================
: -------------------------------------------------------------------
: f1 : demo2.c #50 : operator[] - int array[100] -> 44
: f1 : demo2.c #63 : operator[] - int array[1000] -> 44
: f1 : demo2.c #77 : operator[] - int vector[100] -> 44
: f1 : demo2.c #91 : operator[] - int vector[1000] -> 44
: f1 : demo2.c #105 : operator[] - int string[100] -> 109
: f1 : demo2.c #119 : operator[] - int string[1000] -> 109
: f1 : demo2.c #133 : method at() - int string[100] -> 153
: f1 : demo2.c #147 : method at() - int string[1000] -> 153
: -------------------------------------------------------------------


--- Optimization O3 ---
#==========================================================
# Comparison Group#1 of 1 : access to array, vector, string
#----------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#==========================================================
: -------------------------------------------------------------------
: f1 : demo2.c #50 : operator[] - int array[100] -> 44
: f1 : demo2.c #63 : operator[] - int array[1000] -> 44
: f1 : demo2.c #77 : operator[] - int vector[100] -> 44
: f1 : demo2.c #91 : operator[] - int vector[1000] -> 44
: f1 : demo2.c #105 : operator[] - int string[100] -> 109
: f1 : demo2.c #119 : operator[] - int string[1000] -> 109
: f1 : demo2.c #133 : method at() - int string[100] -> 153
: f1 : demo2.c #147 : method at() - int string[1000] -> 153
: -------------------------------------------------------------------

// =================== File demo.h : BEGIN ====================

#ifndef _DEMO_H
#define _DEMO_H

#include "adapt.h"

void f1 (void);

#endif

// =================== File demo.h : END ======================


// =================== File demo.c : BEGIN ====================

#include "demo.h"

void SetEnvIt ()
{
SetTotalTests (25);
SetScaleAndTotalIterations (10000, 100000);
}


void MeasureIt ()
{
}


void CompareIt ()
{
CompareFunc ("access to array, vector, string", f1);
}

// =================== File demo.c : END ======================

// =================== File demo2.c : BEGIN ====================
#include "demo.h"

//---------------------------
#define TURN_ON_uclock(x) TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, x)

//---------------------------
#define SIZE1 100
#define SIZE2 1000


// ==========================
void f1 (void)
{
// ------ Preparation ------
ostringstream osstr;

const size_t median_index1 = SIZE1/2;
const size_t median_index2 = SIZE2/2;

int int_array1 [SIZE1];
int int_array2 [SIZE2];
for (size_t i = 0; i < SIZE1; i++) int_array1[i] = 10*i;
for (size_t i = 0; i < SIZE2; i++) int_array2[i] = 10*i;

vector<int> int_vector1 (int_array1, int_array1 + sizeof(int_array1)/sizeof(int_array1[0]));

vector<int> int_vector2 (int_array2, int_array2 + sizeof(int_array2)/sizeof(int_array2[0]));

assert (int_vector1.size() == (sizeof(int_array1)/sizeof(int_array1[0])));
assert (int_vector2.size() == (sizeof(int_array2)/sizeof(int_array2[0])));

assert (median_index1 < int_vector1.size());
assert (median_index2 < int_vector2.size());

basic_string<int> int_string1 ((sizeof(int_array1)/sizeof(int_array1[0])), 111);
basic_string<int> int_string2 ((sizeof(int_array2)/sizeof(int_array2[0])), 222);

assert (int_string1.size() == (sizeof(int_array1)/sizeof(int_array1[0])));
assert (int_string2.size() == (sizeof(int_array2)/sizeof(int_array2[0])));

assert (median_index1 < int_string1.size());
assert (median_index2 < int_string2.size());

// -------- [] : int_array1 [100] --------
{
osstr.str(string());
osstr << "operator[] - int array["
<< (sizeof(int_array1)/sizeof(int_array1[0]))
<< "]";

TURN_ON_uclock(osstr.str())
{
int_array1 [median_index1];
}
}

// -------- [] :int_array2 [1000] --------
{
osstr.str(string());
osstr << "operator[] - int array["
<< (sizeof(int_array2)/sizeof(int_array2[0]))
<< "]";

TURN_ON_uclock(osstr.str())
{
int_array2 [median_index2];
}
}


// -------- [] : int_vector1 [100] --------
{
osstr.str(string());
osstr << "operator[] - int vector["
<< int_vector1.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_vector1 [median_index1];
}
}


// -------- [] : int_vector2 [1000] --------
{
osstr.str(string());
osstr << "operator[] - int vector["
<< int_vector2.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_vector2 [median_index2];
}
}


// -------- [] : int_string1 [100] --------
{
osstr.str(string());
osstr << "operator[] - int string["
<< int_string1.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_string1 [median_index1];
}
}


// -------- [] : int_string2 [1000] --------
{
osstr.str(string());
osstr << "operator[] - int string["
<< int_string2.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_string2 [median_index2];
}
}


// -------- at() : int_string1 [100] --------
{
osstr.str(string());
osstr << "method at() - int string["
<< int_string1.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_string1.at(median_index1);
}
}


// -------- at() : int_string2 [1000] --------
{
osstr.str(string());
osstr << "method at() - int string["
<< int_string2.size()
<< "]";

TURN_ON_uclock(osstr.str())
{
int_string2.at(median_index2);
}
}


} // f1

// =================== File demo2.c : END ======================

===========================
Alex Vinokur
mailto:ale...@bigfoot.com

mailto:ale...@go.to

Alex Vinokur

unread,
Mar 11, 2002, 4:40:39 AM3/11/02
to
Performance of the find() algorithm/method in vector, list, set, map

was measured when using C/C++ Program Perfometer at
http://groups.google.com/groups?selm=3C84CF9B.AA99EFA8%40bigfoot.com .

===============================================================


gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp)
compiled by GNU C version 2.95.3 20010315/djgpp (release).

---------
Windows98
===============================================================

--- No optimization ---
#=========================================================

# Comparison Group#1 of 1 : find method vs. find algorithm
#---------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#=========================================================
: ----------------------------------------------------------------------
: f2 : demo3.c #63 : find algorithm - vector size 100 -> 11091
: f2 : demo3.c #75 : find algorithm - list size 100 -> 59514
: f2 : demo3.c #88 : find algorithm - set size 100 -> 145631
: f2 : demo3.c #101 : find method - set size 100 -> 18626
: f2 : demo3.c #114 : find method - map size 100 -> 18991
: f2 : demo3.c #128 : find algorithm - vector size 1000 -> 87894
: f2 : demo3.c #140 : find algorithm - list size 1000 -> 567694
: f2 : demo3.c #153 : find algorithm - set size 1000 -> 1619926
: f2 : demo3.c #166 : find method - set size 1000 -> 24773
: f2 : demo3.c #179 : find method - map size 1000 -> 24474
: ----------------------------------------------------------------------

--- Optimization O1 ---
#=========================================================
# Comparison Group#1 of 1 : find method vs. find algorithm
#---------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#=========================================================
: ----------------------------------------------------------------------
: f2 : demo3.c #63 : find algorithm - vector size 100 -> 4227
: f2 : demo3.c #75 : find algorithm - list size 100 -> 12710
: f2 : demo3.c #88 : find algorithm - set size 100 -> 27015
: f2 : demo3.c #101 : find method - set size 100 -> 2106
: f2 : demo3.c #114 : find method - map size 100 -> 2986
: f2 : demo3.c #128 : find algorithm - vector size 1000 -> 36062
: f2 : demo3.c #140 : find algorithm - list size 1000 -> 153180
: f2 : demo3.c #153 : find algorithm - set size 1000 -> 461163
: f2 : demo3.c #166 : find method - set size 1000 -> 2257
: f2 : demo3.c #179 : find method - map size 1000 -> 2995
: ----------------------------------------------------------------------

--- Optimization O2 ---
#=========================================================
# Comparison Group#1 of 1 : find method vs. find algorithm
#---------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#=========================================================
: ----------------------------------------------------------------------
: f2 : demo3.c #63 : find algorithm - vector size 100 -> 4336
: f2 : demo3.c #75 : find algorithm - list size 100 -> 7350
: f2 : demo3.c #88 : find algorithm - set size 100 -> 25985
: f2 : demo3.c #101 : find method - set size 100 -> 1730
: f2 : demo3.c #114 : find method - map size 100 -> 1905
: f2 : demo3.c #128 : find algorithm - vector size 1000 -> 37089
: f2 : demo3.c #140 : find algorithm - list size 1000 -> 130727
: f2 : demo3.c #153 : find algorithm - set size 1000 -> 458502
: f2 : demo3.c #166 : find method - set size 1000 -> 1945
: f2 : demo3.c #179 : find method - map size 1000 -> 2341
: ----------------------------------------------------------------------

--- Optimization O3 ---
#=========================================================
# Comparison Group#1 of 1 : find method vs. find algorithm
#---------------------------------------------------------


# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock

#=========================================================
: ----------------------------------------------------------------------
: f2 : demo3.c #63 : find algorithm - vector size 100 -> 3987
: f2 : demo3.c #75 : find algorithm - list size 100 -> 6646
: f2 : demo3.c #88 : find algorithm - set size 100 -> 25572
: f2 : demo3.c #101 : find method - set size 100 -> 1639
: f2 : demo3.c #114 : find method - map size 100 -> 1688
: f2 : demo3.c #128 : find algorithm - vector size 1000 -> 35102
: f2 : demo3.c #140 : find algorithm - list size 1000 -> 124117
: f2 : demo3.c #153 : find algorithm - set size 1000 -> 442743
: f2 : demo3.c #166 : find method - set size 1000 -> 1915
: f2 : demo3.c #179 : find method - map size 1000 -> 2182
: ----------------------------------------------------------------------

// =================== File demo.h : BEGIN ====================
#ifndef _DEMO_H
#define _DEMO_H

#include "adapt.h"

#define TURN_ON_uclock(x) TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, x)

void f2 (void);

#endif

// =================== File demo.h : END ======================


// =================== File demo.c : BEGIN ====================
#include "demo.h"

void SetEnvIt ()
{
SetTotalTests (25);
SetScaleAndTotalIterations (10000, 100000);
}


void MeasureIt ()
{
}


void CompareIt ()
{
CompareFunc ("find method vs. find algorithm", f2);
}


// =================== File demo.c : END ======================

// =================== File demo3.c : BEGIN ====================
#include "demo.h"

//---------------------------
#define SIZE_1 100
#define SIZE_2 1000


// ==========================
void f2 (void)


{
// ------ Preparation ------
ostringstream osstr;

const size_t median_value_1 = SIZE_1/2;
const size_t median_value_2 = SIZE_2/2;

vector<int> int_vector_1;
vector<int> int_vector_2;

list<int> int_list_1;
list<int> int_list_2;

set<int> int_set_1;
set<int> int_set_2;

map<int, string> int_map_1;
map<int, string> int_map_2;

for (int i = 0; i < SIZE_1; i++)
{
int_vector_1.push_back(i);
int_list_1.push_back(i);
int_set_1.insert(i);
int_map_1[i] = "AAAAAAAAAA";
}


for (int i = 0; i < SIZE_2; i++)
{
int_vector_2.push_back(i);
int_list_2.push_back(i);
int_set_2.insert(i);
int_map_2[i] = "BBBBBBBBBB";
}

assert (int_vector_1.size() == SIZE_1);
assert (int_list_1.size() == SIZE_1);
assert (int_set_1.size() == SIZE_1);
assert (int_map_1.size() == SIZE_1);

assert (int_vector_2.size() == SIZE_2);
assert (int_list_2.size() == SIZE_2);
assert (int_set_2.size() == SIZE_2);
assert (int_map_2.size() == SIZE_2);


// -------- find algorithm : int_vector_1 --------
{
osstr.str(string());
osstr << "find algorithm - vector size "
<< int_vector_1.size();

TURN_ON_uclock(osstr.str())
{
find (int_vector_1.begin(), int_vector_1.end(), median_value_1);
}
}

// -------- find algorithm : int_list_1 --------
{
osstr.str(string());
osstr << "find algorithm - list size "
<< int_list_1.size();

TURN_ON_uclock(osstr.str())
{
find (int_list_1.begin(), int_list_1.end(), median_value_1);
}
}


// -------- find algorithm : int_set_1 --------
{
osstr.str(string());
osstr << "find algorithm - set size "
<< int_set_1.size();

TURN_ON_uclock(osstr.str())
{
find (int_set_1.begin(), int_set_1.end(), median_value_1);
}
}


// -------- find method : int_set_1 --------
{
osstr.str(string());
osstr << "find method - set size "
<< int_set_1.size();

TURN_ON_uclock(osstr.str())
{
int_set_1.find (median_value_1);
}
}


// -------- find method : int_map_1 --------
{
osstr.str(string());
osstr << "find method - map size "
<< int_map_1.size();

TURN_ON_uclock(osstr.str())
{
int_map_1.find (median_value_1);
}
}

// -------- find algorithm : int_vector_2 --------
{
osstr.str(string());
osstr << "find algorithm - vector size "
<< int_vector_2.size();

TURN_ON_uclock(osstr.str())
{
find (int_vector_2.begin(), int_vector_2.end(), median_value_2);
}
}

// -------- find algorithm : int_list_2 --------
{
osstr.str(string());
osstr << "find algorithm - list size "
<< int_list_2.size();

TURN_ON_uclock(osstr.str())
{
find (int_list_2.begin(), int_list_2.end(), median_value_2);
}
}


// -------- find algorithm : int_set_2 --------
{
osstr.str(string());
osstr << "find algorithm - set size "
<< int_set_2.size();

TURN_ON_uclock(osstr.str())
{
find (int_set_2.begin(), int_set_2.end(), median_value_2);
}
}


// -------- find method : int_set_2 --------
{
osstr.str(string());
osstr << "find method - set size "
<< int_set_2.size();

TURN_ON_uclock(osstr.str())
{
int_set_2.find (median_value_2);
}
}


// -------- find method : int_map_2 --------
{
osstr.str(string());
osstr << "find method - map size "
<< int_map_2.size();

TURN_ON_uclock(osstr.str())
{
int_map_2.find (median_value_2);
}
}

} // f2

// =================== File demo3.c : END ======================

===========================
Alex Vinokur
mailto:ale...@bigfoot.com

mailto:ale...@go.to

Alex Vinokur

unread,
Mar 12, 2002, 5:04:07 AM3/12/02
to
Performance of for-loop and for_each algorithm
in vector, string, list, set

was measured when using C/C++ Program Perfometer at
http://groups.google.com/groups?selm=3C84CF9B.AA99EFA8%40bigfoot.com

===============================================================


gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp)
compiled by GNU C version 2.95.3 20010315/djgpp (release).

---------
Windows98
===============================================================

--- No optimization ---
#================================================
# Comparison Group#1 of 1 : for-loop vs. for_each


#------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#================================================
: -------------------------------------------------------------------------

: f3 : demo3.c #68 : for-loop - vector size 100 -> 60221
: f3 : demo3.c #88 : for-loop - string size 100 -> 554565
: f3 : demo3.c #109 : for-loop - list size 100 -> 348958
: f3 : demo3.c #130 : for-loop - set size 100 -> 468564
: f3 : demo3.c #151 : for_each algorithm - vector size 100 -> 38634
: f3 : demo3.c #169 : for_each algorithm - string size 100 -> 47679
: f3 : demo3.c #187 : for_each algorithm - list size 100 -> 133318
: f3 : demo3.c #205 : for_each algorithm - set size 100 -> 310829
: -------------------------------------------------------------------------

--- Optimization O1 ---
#================================================
# Comparison Group#1 of 1 : for-loop vs. for_each


#------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#================================================
: -------------------------------------------------------------------------

: f3 : demo3.c #68 : for-loop - vector size 100 -> 27802
: f3 : demo3.c #88 : for-loop - string size 100 -> 55053
: f3 : demo3.c #109 : for-loop - list size 100 -> 42867
: f3 : demo3.c #130 : for-loop - set size 100 -> 67939
: f3 : demo3.c #151 : for_each algorithm - vector size 100 -> 31306
: f3 : demo3.c #169 : for_each algorithm - string size 100 -> 32563
: f3 : demo3.c #187 : for_each algorithm - list size 100 -> 36218
: f3 : demo3.c #205 : for_each algorithm - set size 100 -> 68370
: -------------------------------------------------------------------------

--- Optimization O2 ---
#================================================
# Comparison Group#1 of 1 : for-loop vs. for_each


#------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#================================================
: -------------------------------------------------------------------------

: f3 : demo3.c #68 : for-loop - vector size 100 -> 29404
: f3 : demo3.c #88 : for-loop - string size 100 -> 55141
: f3 : demo3.c #109 : for-loop - list size 100 -> 38100
: f3 : demo3.c #130 : for-loop - set size 100 -> 70248
: f3 : demo3.c #151 : for_each algorithm - vector size 100 -> 32006
: f3 : demo3.c #169 : for_each algorithm - string size 100 -> 32522
: f3 : demo3.c #187 : for_each algorithm - list size 100 -> 36340
: f3 : demo3.c #205 : for_each algorithm - set size 100 -> 69047
: -------------------------------------------------------------------------

--- Optimization O3 ---

#================================================
# Comparison Group#1 of 1 : for-loop vs. for_each


#------------------------------------------------
# Resource Name : user time used
# Resource Cost Unit : uclock
# Resource State Unit : uclock
#================================================
: -------------------------------------------------------------------------

: f3 : demo3.c #68 : for-loop - vector size 100 -> 4911
: f3 : demo3.c #88 : for-loop - string size 100 -> 31126
: f3 : demo3.c #109 : for-loop - list size 100 -> 16558
: f3 : demo3.c #130 : for-loop - set size 100 -> 45196
: f3 : demo3.c #151 : for_each algorithm - vector size 100 -> 29931
: f3 : demo3.c #169 : for_each algorithm - string size 100 -> 30789
: f3 : demo3.c #187 : for_each algorithm - list size 100 -> 33768
: f3 : demo3.c #205 : for_each algorithm - set size 100 -> 64397
: -------------------------------------------------------------------------


// =================== File demo.h : BEGIN ====================
#ifndef _DEMO_H
#define _DEMO_H

//---------------------------
#include "adapt.h"

//---------------------------


#define TURN_ON_uclock(x) TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, x)

//---------------------------
void f1 (void);
void f2 (void);
void f3 (void);

#endif

// =================== File demo.h : END ======================


// =================== File demo.c : BEGIN ====================
#include "demo.h"

void SetEnvIt ()
{
SetTotalTests (25);
SetScaleAndTotalIterations (10000, 100000);
}


void MeasureIt ()
{
}


void CompareIt ()
{
CompareFunc ("for-loop vs. for_each", f3);
}


// =================== File demo.c : END ======================

// =================== File demo3.c : BEGIN ====================
#include "demo.h"

//---------------------------
#define SIZE_OF_CONTAINER 100

typedef unsigned int uint;

// ==========================
void foo (int val_i)
{
val_i * 2;
}


// ==========================
void f3 (void)
{
// ------ Preparation ------

const string text_for_loop ("for-loop");
const string text_for_each ("for_each algorithm");
size_t text_find_setw = MAX_VALUE (text_for_loop.size(), text_for_each.size());
size_t text_container_name_setw = 6;


ostringstream osstr;
osstr.setf (ios::left, ios::adjustfield);


vector<uint> uint_vector;
vector<uint>::iterator iter_vector;

basic_string<uint> uint_string;
basic_string<uint>::iterator iter_string;

list<uint> uint_list;
list<uint>::iterator iter_list;

set<uint> uint_set;
set<uint>::iterator iter_set;

for (uint i = 0; i < SIZE_OF_CONTAINER; i++)
{
uint_vector.push_back(i);
uint_string += i;
uint_list.push_back(i);
uint_set.insert(i);
}


assert (uint_vector.size() == SIZE_OF_CONTAINER);
assert (uint_string.size() == SIZE_OF_CONTAINER);
assert (uint_list.size() == SIZE_OF_CONTAINER);
assert (uint_set.size() == SIZE_OF_CONTAINER);


// -------- for-loop : uint_vector --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_loop.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "vector"
<< " size "
<< uint_vector.size();

TURN_ON_uclock(osstr.str())
{
for (iter_vector = uint_vector.begin(); iter_vector != uint_vector.end();
iter_vector++)
{
foo (*iter_vector);
}
}
}

// -------- for-loop : uint_string --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_loop.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "string"
<< " size "
<< uint_string.size();

TURN_ON_uclock(osstr.str())
{
for (iter_string = uint_string.begin(); iter_string != uint_string.end();
iter_string++)
{
foo (*iter_string);
}
}
}


// -------- for-loop : uint_list --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_loop.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "list"
<< " size "
<< uint_list.size();

TURN_ON_uclock(osstr.str())
{
for (iter_list = uint_list.begin(); iter_list != uint_list.end(); iter_list++)
{
foo (*iter_list);
}
}
}


// -------- for-loop : uint_set --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_loop.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "set"
<< " size "
<< uint_set.size();

TURN_ON_uclock(osstr.str())
{
for (iter_set = uint_set.begin(); iter_set != uint_set.end(); iter_set++)
{
foo (*iter_set);
}
}
}


// -------- for_each : uint_vector --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_each.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "vector"
<< " size "
<< uint_vector.size();

TURN_ON_uclock(osstr.str())
{
for_each (uint_vector.begin(), uint_vector.end(), foo);
}
}


// -------- for_each : uint_string --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_each.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "string"
<< " size "
<< uint_string.size();

TURN_ON_uclock(osstr.str())
{
for_each (uint_string.begin(), uint_string.end(), foo);
}
}


// -------- for_each : uint_list --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_each.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "list"
<< " size "
<< uint_list.size();

TURN_ON_uclock(osstr.str())
{
for_each (uint_list.begin(), uint_list.end(), foo);
}
}


// -------- for_each : uint_set --------
{
osstr.str(string());
osstr << setw (text_find_setw)
<< text_for_each.c_str()
<< " - "
<< setw(text_container_name_setw)
<< "set"
<< " size "
<< uint_set.size();

TURN_ON_uclock(osstr.str())
{
for_each (uint_set.begin(), uint_set.end(), foo);
}
}


} // f3

// =================== File demo3.c : END ======================

===========================
Alex Vinokur
mailto:ale...@bigfoot.com
mailto:ale...@go.to

Reply all
Reply to author
Forward
0 new messages