当前位置: 首页>>代码示例>>C++>>正文


C++ Chrono类代码示例

本文整理汇总了C++中Chrono的典型用法代码示例。如果您正苦于以下问题:C++ Chrono类的具体用法?C++ Chrono怎么用?C++ Chrono使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Chrono类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv) {
    Chrono ch;
    Timer tm;
    ch.startChrono();
    fstream logfile;
    logfile.open("results_knapsack.txt", ios::out);
    //remember the limit of the 4gb allocated space
    int dim[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
    int local_threads[] = {0, 64, 128, 256, 512, 1024};


    for (int k = 5; k < sizeof (local_threads) / sizeof (int); k++) {//local_threads
        for (int j = 9; j < sizeof (dim) / sizeof (int); j++) {

            TestData* test = new TestData(dim[j]);
            Knapsack *ksack = new Knapsack(*test);

            //1.Query the host system for OpenCL platform info
            ksack->queryOclPlatformInfo(&logfile);
            //2. Query the host for OpenCL devices
            ksack->queryOclDevice(&logfile);

            for (int i = 0; i < ksack->getNumDevices(); i++) {

                ksack->queryOclDeviceInfo(i, &logfile);
                //3. Create a context and a queue to associate the OpenCL devices.
                ksack->createContextQueue(i, &logfile);
                //4. Create programs that will run on one or more associated devices.
                ksack->createProgramBuild(i, &logfile);
                //5. Create memory objects on the host or on the device.
                //6. Copy memory data to the device as needed. Create memory objects on the host or on the device.
                ksack->createMemObjects(&logfile);
                //7. Create Kernels
                ksack->createKernel();
                //8. Provide arguments for the kernels.
                // ksack.createKernel();
                //9. Submit the kernels to the command queue for execution.
                //10. Copy the results from the device to the host
                //ksack.executeMemObjects();
                
                ksack->executeComputation(i, &logfile, local_threads[k]);
                ksack->printResults(&logfile);

            }
            delete ksack;
            delete test;

        }
    }
    logfile.close();
    //http://stackoverflow.com/questions/14063791/double-free-or-corruption-but-why

    ch.stopChrono();
    tm.stop();
    cout << "CHRONO TIME: " << ch.getTimeChrono() << endl;
    cout << "TIMER TIME: " << tm.getTime();

    return 0;

}
开发者ID:nico-mkhatvari,项目名称:OpenCL,代码行数:60,代码来源:knapsack_main.cpp

示例2: TEST

TEST(Test1, pngWriteDataToMemory) {
	std::cout << "########## Image memory write" << std::endl;

	PngReader pngReaderFromFile;
	FilePngInputStream filePngInputStream(IMAGE1);
	pngReaderFromFile.readFromInputstream(filePngInputStream);

	Chrono chrono;
	PngData pngData(pngReaderFromFile.getWidth(), pngReaderFromFile.getHeight(),
			pngReaderFromFile.getBitDepth(), pngReaderFromFile.getColorType(),
			pngReaderFromFile.getPixelDataRowPointers());
	PngWriter writer(pngData);
	MemoryPngOutputStream memOs;
	writer.writePngToOutputStream(memOs);
	std::cout << "Image write png to memory in " << chrono.elapsedTimeInMs()
			<< " ms, nrOfBytes=" << memOs.getNrOfBytes() << std::endl;

	// Read the data written to memory, and check against the original
	MemoryPngInputStream memoryInputstream(memOs.getBuffer().data(),
			memOs.getNrOfBytes());
	PngReader pngReaderFromMemory;
	pngReaderFromMemory.readFromInputstream(memoryInputstream);

	AssertUtil::equals(pngReaderFromFile, pngReaderFromMemory);
}
开发者ID:robertjacobs,项目名称:mahusandbox,代码行数:25,代码来源:test1.cpp

示例3: main

int main(void){
	Chrono c;
	c.start();
	
	int sum = 1,
		step = 2,
		diagonalcount = 0,
		previousdiagonal = 1,
		dimension = 1001;
		
	while(previousdiagonal < (dimension * dimension)){
		if(diagonalcount == 4){
			diagonalcount = 0;
			step += 2;
		}
		int to_add = previousdiagonal + step;
		sum += to_add;
		previousdiagonal = to_add;
		diagonalcount++;		
	}

	c.stop();
	
	std::cout << "The sum of the numbers on the diagonals in a " << dimension <<  " by " << dimension << " spiral is " << sum << std::endl;
	std::cout << "Found the answer in " << c.time() << " seconds" << std::endl;
	return 0;
}
开发者ID:Lentosy,项目名称:Project-Euler,代码行数:27,代码来源:problem28.cpp

示例4: test_with_ctor

void test_with_ctor()
{
  double msecs = 0.0;
  int c = 0;
  for (; c<10000; ++c) {
    Chrono chrono;
    std::sin(0.0);
    msecs += chrono.elapsed();
  }
  std::cout << "sin(0) in " << (msecs/c) << " milliseconds (average from " << c << " runs)\n";
}
开发者ID:dacap,项目名称:cpp-utils,代码行数:11,代码来源:avg.cpp

示例5: update

void Game::update()
{
    Chrono updateTiming;

    m_state.update();

    m_view.setCenter((m_state.getObjects().getPlayer().getPosition())/VIEW_DELAY_FACTOR);

    m_userInterface.update(m_state);
    m_userInterface.setUpdateTime(updateTiming.get());
}
开发者ID:LittleWhite-tb,项目名称:PaciWar,代码行数:11,代码来源:Game.cpp

示例6: sorteertijd

double sorteertijd(vector<T> &v, SorteerMethode<T>* methode, int ncycli=1){
	double somTijden = 0.0;
	for (int i = 0; i < ncycli; i++){
		vector<T> kopie (v);
		Chrono c;
		c.start();
		(*methode)(kopie);
		c.stop();
		somTijden += c.tijd();
	}
	return somTijden / ncycli;
	
}
开发者ID:AndreasDL,项目名称:Tiwi-Algoritmen1,代码行数:13,代码来源:SorteerMethodeTester.cpp

示例7: main

int main(int argc, char **argv) {
	if (argc < 2) {
		std::cout << "Usage: pgn-app png-in" << std::endl;
		return 1;
	}

	Chrono chrono;

	chrono.reset();
	IOUtils png;
	png.readFile(argv[1]);
	MemoryPngInputStream memoryInputstream((const png_bytep) png.getBuffer(),
			(const png_size_t) png.getLength());
	std::cout << "Image read info memory in " << chrono.elapsedTimeInMs()
			<< " ms" << std::endl;

	{
		chrono.reset();
		PngReader rdrMem;
		memoryInputstream.reset();
		rdrMem.readFromInputstream(memoryInputstream, true);
		std::cout << "Image read memory (own alloc)in "
				<< chrono.elapsedTimeInMs() << " ms" << std::endl;
	}

	chrono.reset();
	PngReader rdrMem;
	memoryInputstream.reset();
	rdrMem.readFromInputstream(memoryInputstream);
	std::cout << "Image read memory (pnglib alloc) in "
			<< chrono.elapsedTimeInMs() << " ms" << std::endl;

	PngData pngData(rdrMem.getWidth(), rdrMem.getHeight(), rdrMem.getBitDepth(),
			rdrMem.getColorType(), rdrMem.getPixelDataRowPointers());
	std::cout << "Nr of bytes pixelData=" << pngData.getNrOfBytesPixelData()
			<< std::endl;

	// Loop to see if having a preallocated buffer works better. Answer: yes
	// Saving was 0-20 ms (on VM on Laptop: (windows7,[email protected] ghz, 8gb)
	const uint32_t estimatedPngHeaderSize = 1024 * 8;
	for (int j = 0; j < 10; j++) {
		for (uint32_t i = 0; i < 2; i++) {
			uint32_t outputBufferSize = pngData.getNrOfBytesPixelData()
					+ estimatedPngHeaderSize;
			MemoryPngOutputStream memOs(i * outputBufferSize);
			chrono.reset();
			PngWriter writer(pngData);
			writer.writePngToOutputStream(memOs);
			std::cout << "Iteration: " << i << ", image write png to memory in "
					<< chrono.elapsedTimeInMs() << " ms and has size "
					<< memOs.getNrOfBytes() << " bytes" << std::endl;
		}
	}

	return 0;
}
开发者ID:robertjacobs,项目名称:mahusandbox,代码行数:56,代码来源:main.cpp

示例8: InitModels

void MyGLWindow::InitModels()
{
	Chrono chrono;

	// load models
	ModelLoader modelLoader;

	chrono.start();
	_actorLib["Tank"] = modelLoader.LoadFromFile("./data/model/stankbot/models/stankbot.dae");
	_actorLib["Tank"]->SetShaderProgram(_shaderProgLib["defaultShader"]);
	std::cout << "Load stankbot (ms) : " << chrono.ellapsed() << std::endl;

	chrono.start();
	_actorLib["Dragon"] = modelLoader.LoadFromFile("./data/model/dragon_vrip_res3.ply");
	_actorLib["Dragon"]->SetShaderProgram(_shaderProgLib["defaultShader"]);
	std::cout << "Load dragon (ms) : " << chrono.ellapsed() << std::endl;
}
开发者ID:remia,项目名称:marching_cube,代码行数:17,代码来源:MyGLWindow.cpp

示例9: render

void Game::render()
{
    Chrono drawTiming;

    m_targetWindow.clear(sf::Color::Black);
    m_targetWindow.setView(m_view);

    m_state.getObjects().draw(m_targetWindow);
    m_state.getBorders().draw(m_targetWindow);


    m_targetWindow.setView(m_targetWindow.getDefaultView());
    m_userInterface.draw(m_targetWindow);

    m_targetWindow.display();
    m_userInterface.setDrawTime(drawTiming.get());
}
开发者ID:LittleWhite-tb,项目名称:PaciWar,代码行数:17,代码来源:Game.cpp

示例10: main

int main(int argc, char *argv[])
{
    srand(time(0));
    Sortvector<int> temp(10);
    temp.shuffle();
    
    //Start het hele sorteer-circus
    Chrono chr;

    cout<<"Insertion sort"<<endl;
    vector<int> vec1 = temp;
    InsertionSort<int> ins_sort;
    chr.start();
    ins_sort(vec1);
    chr.stop();
    cout<<"Insertion sort duurde "<<chr.tijd()<<"."<<endl;
    
    cout<<"STL sort"<<endl;
    vec1 = temp;
    STLSort<int> stl_sort;
    chr.start();
    stl_sort(vec1);
    chr.stop();
    cout<<"Insertion sort duurde "<<chr.tijd()<<"."<<endl;

    return 0;
}
开发者ID:jelledebock,项目名称:algo,代码行数:27,代码来源:oef2.cpp

示例11: waitForMessage

void ClientInterface::waitForMessage(){
	Chrono chrono;

	chrono.start();

	while(getNextMessageType()==nmtInvalid){

		if(!isConnected()){
			throw runtime_error("Disconnected");
		}

		if(chrono.getMillis()>messageWaitTimeout){
			throw runtime_error("Timeout waiting for message");
		}

		sleep(waitSleepTime);
	}
}
开发者ID:wangtianhang,项目名称:glest,代码行数:18,代码来源:client_interface.cpp

示例12: waitUntilReady

void ClientInterface::waitUntilReady(Checksum* checksum){
	
	NetworkMessageReady networkMessageReady;
	Chrono chrono;

	chrono.start();

	//send ready message
	sendMessage(&networkMessageReady);

	//wait until we get a ready message from the server
	while(true){
		
		NetworkMessageType networkMessageType= getNextMessageType();

		if(networkMessageType==nmtReady){
			if(receiveMessage(&networkMessageReady)){
				break;
			}
		}
		else if(networkMessageType==nmtInvalid){
			if(chrono.getMillis()>readyWaitTimeout){
				throw runtime_error("Timeout waiting for server");
			}
		}
		else{
			throw runtime_error("Unexpected network message: " + intToStr(networkMessageType) );
		}

		// sleep a bit
		sleep(waitSleepTime);
	}

	//check checksum
	if(Config::getInstance().getBool("NetworkConsistencyChecks")){
		if(networkMessageReady.getChecksum()!=checksum->getSum()){
			throw runtime_error("Checksum error, you don't have the same data as the server");
		}
	}

	//delay the start a bit, so clients have nore room to get messages
	sleep(GameConstants::networkExtraLatency);
}
开发者ID:wangtianhang,项目名称:glest,代码行数:43,代码来源:client_interface.cpp

示例13: main

int main(int argc, char **argv) {
	Random rand; // default constructor seeds with 0

	fixed fixed_numbers[NUM_TRIALS];
	fixed fixed_roots[NUM_TRIALS];

	float float_numbers[NUM_TRIALS];
	float float_roots[NUM_TRIALS];

	for (int i=0; i < NUM_TRIALS; ++i) {
		fixed_numbers[i] = rand.randRange(4, 4000);
		fixed_numbers[i] += rand.randRange(0, 4095) / fixed(4096);
		
		float_numbers[i] = fixed_numbers[i].toFloat();
	}
	{	// using floats and sqrtf(), for reference
		Chrono chrono;
		chrono.start();
		for (int i=0; i < NUM_TRIALS; ++i) {
			float_roots[i] = sqrtf(float_numbers[i]);
		}
		chrono.stop();
		cout << "\nDone, " << NUM_TRIALS << " floating point square roots.  Took " << chrono.getMicros() << "us";
	}
	DO_TEST(sqRt_c);
	DO_TEST(sqRt_unrolled_once);
	DO_TEST(sqRt_unrolled_twice);
	DO_TEST(sqRt_unrolled_thrice);
	DO_TEST(sqRt_unrolled_completely);
	DO_TEST(sqRt_julery);
	DO_TEST(sqRt_julery_crowne);

	cout << "\n\n[Enter]";
	char boo[8];
	std::cin.getline(boo, 8);

}
开发者ID:MoLAoS,项目名称:Mandate,代码行数:37,代码来源:test2_main.cpp

示例14: SetValue

void xPLCron::SetValue(Chrono& chrono, const string& value)
{
    xPL::SchemaControlBasic sendCmnd;
    string moduleName;
    string deviceName;
    string deviceType;


  	LOG_ENTER;

    moduleName = chrono.GetModuleName();
    deviceName = chrono.GetDeviceName();
    deviceType = chrono.GetDeviceType();

    chrono.SetValue(value);
    sendCmnd.SetDeviceType(deviceType);
    sendCmnd.SetDeviceName(deviceName);
    sendCmnd.SetCurrent(value);

    LOG_VERBOSE(m_Log) << "Send " << value << " to " << moduleName << " device " << deviceName;
    m_xPLDevice.SendMessage(&sendCmnd, moduleName);

   	LOG_EXIT_OK;
}
开发者ID:FragJage,项目名称:xPLCron,代码行数:24,代码来源:xPLCron.cpp

示例15: launch_bench_square

void launch_bench_square(Field & F // const problem
			 , size_t min, size_t max, size_t step // no negative step
			 , PlotData & Data
			)
{
	linbox_check(step);
	linbox_check(min <= max);

	std::ostringstream nam ;
	F.write(nam);
	// Data.setCurrentSeriesName(nam.str());

	Data.newSeries(nam.str());
	Chrono<Timer> TW ;

	typedef typename Field::RandIter Randiter ;
	Randiter R(F) ;
	BlasMatrixDomain<Field> BMD(F) ;
	RandomDenseMatrix<Randiter,Field> RandMat(F,R);

	for ( size_t i = min ; i < max ; i += step ) {

		showAdvanceLinear(i,min,max);
		size_t ii = i ;
		BlasMatrix<Field> A (F,ii,ii);
		BlasMatrix<Field> B (F,ii,ii);
		BlasMatrix<Field> C (F,ii,ii);

		size_t j = 0 ; // number of repets.

		RandMat.random(A);
		RandMat.random(B);
		RandMat.random(C);
		TW.clear() ;
		while( Data.keepon(j,TW.time(),false) ) {
			TW.start() ;
			BMD.mul(C,A,B) ; // C = AB
			TW.stop();
			++j ;
		}
		double mflops = computeMFLOPS(TW.times(),mm_mflops(i,i,i));

		Data.setCurrentSeriesEntry(i,mflops,(double)i,TW.time()); // could be i*i*i

	}

	Data.finishSeries();
}
开发者ID:cbouilla,项目名称:linbox,代码行数:48,代码来源:benchmark-example.C


注:本文中的Chrono类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。