本文整理汇总了C++中Stopwatch::user方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::user方法的具体用法?C++ Stopwatch::user怎么用?C++ Stopwatch::user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateRand_3
void generateRand_3(int array[], int arraySize)
{
Stopwatch stopWatch;
int i;
for (i=0; i<arraySize; i++) //fill array first
{
array[i] = i+1;
}
stopWatch.start();
for (i=1; i<arraySize; i++) //now randomly swap stuff
{
swap(array[i], array[ array[i] = (int)(rand()*rand() % arraySize) ]);
}
stopWatch.stop();
displayStats(arraySize, stopWatch.user(), stopWatch.user()/arraySize);
}
示例2: generateRand_1
void generateRand_1(int array[], int arraySize)
{
Stopwatch stopWatch;
bool bad = false; //a flag for checking to see if a certain number was already in another element.
stopWatch.start();
for (int i=0; i<arraySize; i++)
{
do
{
array[i] = (int)(rand()*rand() % arraySize); //Assign a random value to array[i]
bad = false; //set bad flag to false
for (int j=0; j<i; j++) //check each element up to current one
{
if ((int)array[i] == (int)array[j]) //if there is already one similar
{
bad = true; //make bad flag true.
}
}
} while ( bad ); //keep assigning new numbers until it's not bad.
}
stopWatch.stop();
displayStats(arraySize, stopWatch.user(), stopWatch.user()/(arraySize * arraySize * log10(arraySize)));
}
示例3: generateRand_2
void generateRand_2(int array[], int arraySize)
{
Stopwatch stopWatch;
int i; //for the loops
bool used[arraySize]; //array to hold whether a number has been used
for (i=0; i<arraySize; i++) { used[i] = false; } //initialize array
for (i=0; i<arraySize; i++)
{
array[i] = (int)(rand()*rand() % arraySize); //Assign random value
if ( i > 0 )
{
//Check to see if that number was already used
while ( used[ array[i] ] == true )
{
array[i] = (int)(rand()*rand() % arraySize);
}
}
used[ array[i] ] = true;
}
stopWatch.stop();
displayStats(arraySize, stopWatch.user(), stopWatch.user()/(arraySize * log10(arraySize)));
}