本文整理汇总了C++中StopWatch类的典型用法代码示例。如果您正苦于以下问题:C++ StopWatch类的具体用法?C++ StopWatch怎么用?C++ StopWatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StopWatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
std::cout << "Boost.Statechart StopWatch example\n\n";
std::cout << "s<CR>: Starts/Stops stop watch\n";
std::cout << "r<CR>: Resets stop watch\n";
std::cout << "d<CR>: Displays the elapsed time in seconds\n";
std::cout << "e<CR>: Exits the program\n\n";
std::cout << "You may chain commands, e.g. rs<CR> resets and starts stop watch\n\n";
StopWatch stopWatch;
stopWatch.initiate();
char key = GetKey();
while ( key != 'e' )
{
switch( key )
{
case 'r':
{
stopWatch.process_event( EvReset() );
}
break;
case 's':
{
stopWatch.process_event( EvStartStop() );
}
break;
case 'd':
{
double elapsedTime = 0.0;
stopWatch.process_event( EvGetElapsedTime( elapsedTime ) );
std::cout << "Elapsed time: " << elapsedTime << "\n";
}
break;
default:
{
std::cout << "Invalid key!\n";
}
break;
}
key = GetKey();
}
return 0;
}
示例2: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
uint32_t goalsize = 6144; // 6GB
_ASSERTE(create_very_big_file(L"big.txt",goalsize));//목표크기 6GB만큼 파일 생성
StopWatch sw;
sw.Start();
_ASSERTE(file_copy_using_read_write(L"big.txt", L"big2.txt"));
sw.Stop();
print("info] (Read Write) time elapsed = %f", sw.GetDurationSecond());
LARGE_INTEGER _Filesize;
_Filesize.QuadPart = (LONGLONG)(1024*1024)*(LONGLONG)goalsize;//파일의 크기 6GB 설정하기위해 LARGE_INTEGER
DWORD bufS = 4096; // read.write에서 buf가 4096이므로 4096설정
PUCHAR buf = (PUCHAR)malloc(bufS);
LARGE_INTEGER _Offset;
_Offset.QuadPart = 0; //파일을 옮겨주는 계산을 하는데 사용한다.
StopWatch sw2;
sw2.Start();
FileIoHelper FileHelp;
FileHelp.FIOpenForRead(L"big.txt");
FileHelp.FIOCreateFile(L"big3.txt", _Filesize);
while(_Filesize.QuadPart > _Offset.QuadPart)
{
if((_Filesize.QuadPart - _Offset.QuadPart) > (LONGLONG)bufS)
bufS = 4096;
else
bufS = (DWORD)(_Filesize.QuadPart - _Offset.QuadPart);
FileHelp.FIOReadFromFile(_Offset, bufS, buf);
FileHelp.FIOWriteToFile(_Offset, bufS, buf);
_Offset.QuadPart += (LONGLONG)bufS;
}
sw2.Stop();
print("info] (Memory Map) time elapsed = %f", sw2.GetDurationSecond());
return 0;
}
示例3: loadOneSSBBinFile
boost::shared_ptr<FMainMemoryBTree> loadOneSSBBinFile(
char *buffer, FSignatureSet &signatureFile, const std::string &dataFolder,
TableType tableType, int64_t maxSize, const std::string &tblFolder, const std::string &tblName, bool cstore) {
boost::shared_ptr<FMainMemoryBTree> btreePtr(new FMainMemoryBTree(tableType, maxSize, false));
FMainMemoryBTree *btree = btreePtr.get();
scoped_array<char> keyBufferPtr(new char[toKeySize(tableType)]);
char *keyBuffer = keyBufferPtr.get();
::memset (keyBuffer, 0, toKeySize(tableType));
ExtractKeyFromTupleFunc extractFunc = toExtractKeyFromTupleFunc(tableType);
StopWatch watch;
watch.init();
std::string filename = tblFolder + tblName;
LOG (INFO) << "reading " << filename << "...";
std::ifstream file(filename.c_str(), std::ios::in | std::ios::binary);
if (!file) {
LOG (ERROR) << "could not open " << filename;
throw std::exception();
}
size_t maxBufCount = IO_BUFFER_SIZE / btree->getDataSize();
size_t maxBufSize = maxBufCount * btree->getDataSize();
assert (maxBufSize <= IO_BUFFER_SIZE);
int count = 0;
while (true) {
file.read (buffer, maxBufSize);
size_t readSize = file.gcount();
for (size_t pos = 0; pos + btree->getDataSize() <= readSize; pos += btree->getDataSize()) {
if (++count % 100000 == 0) {
LOG (INFO) << "reading " << count;
}
extractFunc (buffer + pos, keyBuffer);
btree->insert(keyBuffer, buffer + pos);
}
if (readSize < maxBufSize) break;
}
LOG(INFO) << "read " << count << " lines";
btree->finishInserts();
file.close();
watch.stop();
LOG(INFO) << "constructred main memory BTree (" << watch.getElapsed() << " micsosec for reading and constructing). writing to disk...";
if (cstore) {
LOG (INFO) << "cstore";
signatureFile.dumpToNewCStoreFiles(dataFolder, tblName, *btree);
} else {
LOG (INFO) << "rowstore";
signatureFile.dumpToNewRowStoreFile(dataFolder, tblName + ".db", *btree);
}
return btreePtr;
}
示例4: InitLights
void MVC_Model::InitLights(void)
{
#ifdef _DEBUG
StopWatch initTimer;
initTimer.startTimer();
std::cout << "Loading " << m_lightSONFile << "... ";
#endif
m_lights = LoadLight(m_lightSONFile);
#ifdef _DEBUG
std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
#endif
}
示例5: InitGameObjects
void MVC_Model::InitGameObjects()
{
#ifdef _DEBUG
StopWatch initTimer;
initTimer.startTimer();
std::cout << "Loading " << m_goSONFile << "... ";
#endif
goList = LoadGameObject(m_goSONFile, meshList);
#ifdef _DEBUG
std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
#endif
}
示例6: TestLoggingOverhead_SingleThreaded_Synchronisation
int TestLoggingOverhead_SingleThreaded_Synchronisation() {
// First initialization, using defaults from Boost logging.
BoostLogging::InitAddCommonAttributes();
BoostLogging::InitSetLogLevelToDebug();
BoostLogging::InitLogToDevNullSynchronized();
const int max = 1000000;
{
// debug messages are processed and written to /dev/null, because min level is debug
StopWatch stopWatch;
BoostLogging::LogDebugMessageManyTimes(max);
std::cout << "Writing debug message to /dev/null synchronized): elapsed time: " << stopWatch.ElapsedSeconds().count()
<< ", max: " << max << std::endl;
}
return OutcomeIsOk();
示例7: InitSounds
void MVC_Model::InitSounds()
{
#ifdef _DEBUG
StopWatch initTimer;
initTimer.startTimer();
std::cout << "Loading " << m_soundSONFile << "... ";
#endif
soundList = LoadSounds(m_soundSONFile);
#ifdef _DEBUG
std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
#endif
}
示例8: atoi
bool LZ2DataRunner::run(Globals* g, const vector<string>& args) {
if(args.size()<2){
cout << "at least two arguments! " <<endl;
return false;
}
_file = args[0].c_str();
int testnum = atoi(args[1].c_str());
cout << "LZ2DataRunner: Running file " << _file << endl;
bool success=true;
int i=0;
for (; i< 30; i++)
if (strncmp(_file+i, "dnatest",7) == 0) {
break;
}
char* temp = new char[30];
sprintf(temp, "test%dLZ%s", testnum, (_file+i+8));
char* fn = new char[30];
sprintf(fn, "test2LZ%s", (_file+i+8));
StopWatch stopWatch;
stopWatch.start();
NOBDBAM* am = new NOBDBAM( fn, 1);
LZDataSource* ds=new LZDataSource(am, false);
HashSum* hashAgg = new HashSum((Operator*) ds, 0, (Operator*) ds, 0);
hashAgg->setHashFunction(new IdentityHashFunction(200));
hashAgg->setHashTableSize(200);
Operator* srcs[1]={hashAgg};
int numCols[1]={2};
char* temp3 = new char[30];
sprintf(temp3, "%s.out", temp);
BlockPrinter* bPrint=new BlockPrinter(srcs, numCols, 1, temp3);
bPrint->printColumns();
sprintf(temp3, "test%dLZ.dat", testnum);
ofstream flStream;
flStream.open(temp3, ios::out | ios::app);
flStream.seekp(ios::end);
flStream << "xval: " << (_file+i+8) << endl;
stopWatch.stopToFile(temp3);
flStream.close();
return success;
}
示例9: main
int main()
{
using::Journey::Client;
using::Journey::ClientError;
Client client;
ClientError error = client.geterror();
if (error == Journey::CLERR_NOERROR)
{
uint16_t dpf = 4;
uint16_t remain = 0;
using::Util::StopWatch;
StopWatch swatch;
while (client.receive())
{
remain += swatch.evaluate();
while (remain > dpf - 1)
{
client.update(dpf);
remain -= dpf;
}
client.draw();
}
}
else
{
switch (error)
{
case Journey::CLERR_NXFILES:
showerror("Error: Could not find valid game files.");
break;
case Journey::CLERR_CONNECTION:
showerror("Error: Could not connect to server.");
break;
case Journey::CLERR_WINDOW:
showerror("Error: Could not initialize graphics.");
break;
case Journey::CLERR_AUDIO:
showerror("Error: Could not initialize audio.");
break;
}
while (true) {}
}
return 0;
}
示例10: testQueuePop
static double testQueuePop()
{
StopWatch stopWatch;
for(std::size_t iter = 0; iter != testing::STANDARD_SPEED_ITERS; ++iter) {
std::queue<std::size_t> queue;
for(std::size_t count = 0; count != testing::STANDARD_SPEED_COUNT; ++count) {
queue.push(count);
}
stopWatch.start();
for(std::size_t count = 0; count != testing::STANDARD_SPEED_COUNT; ++count) {
queue.pop();
}
stopWatch.stop();
}
return testing::calcNanosPer(getTimevalAsMicros(stopWatch.elapsed()));
}
示例11: functionRun
AJValue JSC_HOST_CALL functionRun(ExecState* exec, AJObject*, AJValue, const ArgList& args)
{
StopWatch stopWatch;
UString fileName = args.at(0).toString(exec);
Vector<char> script;
if (!fillBufferWithContentsOfFile(fileName, script))
return throwError(exec, GeneralError, "Could not open file.");
AJGlobalObject* globalObject = exec->lexicalGlobalObject();
stopWatch.start();
evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName));
stopWatch.stop();
return jsNumber(globalObject->globalExec(), stopWatch.getElapsedMS());
}
示例12: TestFloat
/*
????TestFloat 1074.285570 / 10000000 = 0.000107
????TestFloat2 30.188889 / 10000000 = 0.000003
*/
void OtherTest::TestFloat()
{
const int count=10000000;
float f=1.73f;
float outi;
StopWatch watch;
watch.SetRunTimes(count);
watch.SetName("TestFloat");
watch.Start();
FOR_EACH_SIZE(i,count)
{
float r= modf(f,&outi);
int ii=(int)outi;
}
示例13: run
void PercolationStats::run()
{
int i;
// perform T independent computational experiments on an N-by-N grid
StopWatch watch;
for (int i = 0; i < m_experimentsNumber; i++) {
watch.start();
m_threshold[i] = experiment();
m_time[i] = watch.stop();
m_percolation->reset();
}
// Stats
m_timeStats = new StatsData(m_time, m_experimentsNumber);
m_thresholdStats = new StatsData(m_threshold, m_experimentsNumber);
}
示例14: run
// run the plan
void Plan::run(bool rosOnly)
{
if (m_lpRootNode != NULL)
{
StopWatch stopWatch;
stopWatch.start();
m_lpRootNode->run(rosOnly);
cout << "Query took: " << stopWatch.stop() << " ms" << endl;
}
else
{
cout << "No plan generated" << endl;
}
}
示例15: testGetInSeconds
void
testGetInSeconds()
{
StopWatch sw;
// 2 s
timespec delay;
delay.tv_sec = static_cast<time_t>(2);
delay.tv_nsec = static_cast<long>(0*1E9);
sw.start();
nanosleep(&delay, NULL);
sw.stop();
CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(round(sw.getInSeconds())) );
}