本文整理汇总了C++中CPUTimer::getCPUTotalSecs方法的典型用法代码示例。如果您正苦于以下问题:C++ CPUTimer::getCPUTotalSecs方法的具体用法?C++ CPUTimer::getCPUTotalSecs怎么用?C++ CPUTimer::getCPUTotalSecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPUTimer
的用法示例。
在下文中一共展示了CPUTimer::getCPUTotalSecs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, const char * argv[] )
{
int n_itrs = MAX;
#ifdef SHOW_QS
mpz_class quoc;
#endif
if( argc > 1 )
n_itrs = atoi( argv[1] );
#ifdef TIME
CPUTimer timer;
unsigned int runs = 0;
#endif
for(int x = -n_itrs; x < n_itrs; ++x)
for(int y = -n_itrs; y < n_itrs; ++y)
{
if( y == x )
continue;
Quociente q( x , y ) ;
for(int k = 1 ; k < n_itrs; ++k)
{
std::cout << "x[" << x << "] y[" << y << "] k[" << k << "]\n";
#ifdef TIME
timer.start();
#endif
#ifdef SHOW_QS
quoc = q.FindFor( k );
#else
q.FindFor( k );
#endif
#ifdef TIME
timer.stop();
runs++;
std::cout << "\tTrial time: " << timer.getCPUCurrSecs() << "s" << std::endl;
#endif
#ifdef SHOW_QS
std::cout << "\tQuocient: " << quoc << std::endl;
#endif
}
}
#ifdef TIME
std::cout << "\n\nTotal time: " << timer.getCPUTotalSecs() << "s" << std::endl;
std::cout << "Avg. time : " << timer.getCPUTotalSecs()/runs << "s" << std::endl;
#endif
return 0;
}
示例2: main
int main(){
unsigned int n_lines, max_val, i, ret, a = 0, b = 0, c = 0;
bst_ret b_ret;
char op;
bst * h = NULL;
scanf(" %u %u", &n_lines, &max_val);
/* Create the binary tree */
b_ret = bst_create(&h, n_lines);
if(b_ret == bst_NoMem){
printf("ERROR: No memory to create bst tree!\n");
printf("\t\tSize: %u\n", n_lines);
exit(1);
}
/* Intiatializing time variables */
insTime.reset();
searchTime.reset();
remTime.reset();
/* Read the input file */
for(i = 0; i < n_lines; i++){
scanf(" %c %*d %[^\n]", &op, set);
switch( op ){
/* Insertion */
case 'i':
ret = insert(h, set);
#ifdef _LOG
if( ret == OP_OK )
printf("i OK %s\n", set);
else if( ret == PREV_INSERTED )
printf("i PREV %s\n", set);
else if( ret == BST_FULL) {
printf("ERROR: bst if full!\n\tcould not insert %s\n", set);
exit( 1 );
}
#endif
a++;
break;
/* Search */
case 'b':
ret = search(h, set);
#ifdef _LOG
if( ret == OP_OK )
printf("b FND %s\n", set);
else
printf("b ~FND %s\n", set);
#endif
b++;
break;
/* Removal */
case 'r':
ret = _delete(h, set);
#ifdef _LOG
if( ret == OP_OK )
printf("r OK %s\n", set);
else
printf("r ~FND %s\n", set);
#endif
c++;
break;
/* Wrong code */
default:
printf("ERROR: Wrong input at line %u!\n", i+1);
exit(1);
}
}
if(a == 0)
a++;
if(b == 0)
b++;
if(c == 0)
c++;
printf("\n\nSTATISTICS\n==========\n\n");
/* Insertion */
printf(" Insertion Total Time: %lfs\n\tInsertion Average Time: %.12lfms\n",
insTime.getCPUTotalSecs(), (insTime.getCPUTotalSecs() / a) * 1000 );
/* Search */
printf(" Search Total Time: %lfs\n\tSearch Average Time: %.12lfms\n",
searchTime.getCPUTotalSecs(), (searchTime.getCPUTotalSecs() / b) * 1000 );
/* Removal */
printf(" Remove Total Time: %lfs\n\tRemove Average Time: %.12lfms\n",
remTime.getCPUTotalSecs(), (remTime.getCPUTotalSecs() / c) * 1000 );
/* Total running time */
printf("Total Running time: %lfs\n", ( remTime.getCPUTotalSecs() +
searchTime.getCPUTotalSecs() + insTime.getCPUTotalSecs() ) );
bst_destroy(h);
//.........这里部分代码省略.........
示例3: main
/**
* Reads in the input file, performs the KP-frac linear time strategy on the
* input and displays the optimal solution.
*/
int main (int argc, char * argv[]) {
if (argc <= 1) {
std::cout << "Please indicate the name of the input file." << std::endl;
return -1;
}
CPUTimer timer;
std::cout << "Instance, Avg Running Time (s), Number of Iterations, Value" << std::endl;
for (int fileIdx = 1; fileIdx < argc; fileIdx++) {
parser(argv[fileIdx]);
Object * temp = new Object[num_elem];
for (int i = 0; i < num_elem; i++)
temp[i] = objects[i];
timer.reset();
int it = 0;
while (timer.getCPUTotalSecs() < 5.0)
{
inserted.clear();
timer.start();
kpfrac_linear(objects, num_elem, W);
timer.stop();
it++;
for(int j = 0; j < num_elem; j++)
objects[j] = temp[j];
}
double media = timer.getCPUTotalSecs() / it;
std::cout << argv[fileIdx] << "," << media << "," << it;
// Loop over the array of objects and display which were inserted and with
// what frequency.
double totalValue = 0;
#ifdef DEBUG
std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
#endif
for (int i = 0, len = inserted.size(); i < len; i++) {
Object obj = inserted[i];
#ifdef DEBUG
std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
std::cout << obj.elem << " " << obj.value << " "
<< obj.weight << " " << obj.density << " "
<< obj.frequency << std::endl;
#endif
totalValue += obj.frequency * obj.value;
}
std::cout << std::setprecision(15) << "," << totalValue << std::endl;
delete [] objects;
inserted.clear();
}
return 0;
}