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


C++ SimpleTimer::stop方法代码示例

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


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

示例1: runKDTreePerformanceTests

int runKDTreePerformanceTests()
{
	std::cout << "Setup..." << std::endl; // DEBUG.

	SimpleTimer timer;

	mesh *obj_mesh = new mesh( "meshes\\bunny_small_0.obj" );

	float fovy = 45.0f;
	glm::vec2 reso( 256, 256 );
	glm::vec3 eyep( 0.5f, 0.5f, 1.0f );
	glm::vec3 vdir( 0.0f, 0.0f, -1.0f );
	glm::vec3 uvec( 0.0f, 1.0f, 0.0f );
	Camera *camera = new Camera( fovy, reso, eyep, vdir, uvec );

	BMP output_img;
	output_img.SetSize( ( int )reso.x, ( int )reso.y );
	output_img.SetBitDepth( 24 );

	float time_elapsed;
	std::string output_img_path;


	////////////////////////////////////////////////////
	// CPU brute force.
	////////////////////////////////////////////////////

	std::cout << "CPU brute force..." << std::endl; // DEBUG.

	timer.start();

	// Iterate through all pixels.
	for ( int y = 0; y < reso.y; ++y ) {
		for ( int x = 0; x < reso.x; ++x ) {
			Ray ray = camera->computeRayThroughPixel( x, y );
			glm::vec3 pixel_color = bruteForceMeshTraversal( obj_mesh, ray );

			// Write pixel.
			output_img( x, y )->Red = ( ebmpBYTE )( pixel_color.x * 255.0f );
			output_img( x, y )->Green = ( ebmpBYTE )( pixel_color.y * 255.0f );
			output_img( x, y )->Blue = ( ebmpBYTE )( pixel_color.z * 255.0f );
		}
	}

	time_elapsed = timer.stop();
	std::cout << "TRAVERSAL - CPU brute force: " << time_elapsed << std::endl;

	output_img_path = "ray_casting_output\\cpu_brute_force.bmp";
	output_img.WriteToFile( output_img_path.c_str() );


	////////////////////////////////////////////////////
	// CPU stack.
	////////////////////////////////////////////////////

	std::cout << "CPU stack..." << std::endl; // DEBUG.

	timer.start();
	KDTreeCPU *kd_tree = new KDTreeCPU( obj_mesh->numTris, obj_mesh->tris, obj_mesh->numVerts, obj_mesh->verts );
	time_elapsed = timer.stop();
	std::cout << "CONSTRUCTION - CPU kd-tree: " << time_elapsed << std::endl;

	timer.start();

	// Iterate through all pixels.
	for ( int y = 0; y < reso.y; ++y ) {
		for ( int x = 0; x < reso.x; ++x ) {
			Ray ray = camera->computeRayThroughPixel( x, y );
			glm::vec3 pixel_color = kdTreeMeshTraversal( kd_tree, ray );

			// Write pixel.
			output_img( x, y )->Red = ( ebmpBYTE )( pixel_color.x * 255.0f );
			output_img( x, y )->Green = ( ebmpBYTE )( pixel_color.y * 255.0f );
			output_img( x, y )->Blue = ( ebmpBYTE )( pixel_color.z * 255.0f );
		}
	}

	time_elapsed = timer.stop();
	std::cout << "TRAVERSAL - CPU stack: " << time_elapsed << std::endl;

	output_img_path = "ray_casting_output\\cpu_stack.bmp";
	output_img.WriteToFile( output_img_path.c_str() );


	////////////////////////////////////////////////////
	// CPU stackless with CPU structs.
	////////////////////////////////////////////////////

	std::cout << "CPU stackless with CPU structs..." << std::endl; // DEBUG.

	timer.start();
	kd_tree->buildRopeStructure();
	time_elapsed = timer.stop();
	std::cout << "CONSTRUCTION - CPU kd-tree rope structure: " << time_elapsed << std::endl;

	timer.start();

	// Iterate through all pixels.
	for ( int y = 0; y < reso.y; ++y ) {
		for ( int x = 0; x < reso.x; ++x ) {
//.........这里部分代码省略.........
开发者ID:jeremynewlin,项目名称:Accel,代码行数:101,代码来源:main.cpp

示例2: main

int  main()
   {
    SelSorter dateObjectI1;
    MrgSorter dateObjectM1;
    QkSorter dateObjectQ1;
    DateType dateValue;
    SimpleTimer timer;
    char tempString[ SMALL_STR_LEN ], insTime[ SMALL_STR_LEN ];
    char qkTime[ SMALL_STR_LEN ], mrgTime[ SMALL_STR_LEN ]; 
    bool qSortGood = false, mSortGood = false, iSortGood = false;

    // load dates ////////////////////////////////////////////////////////////
    cout << endl << "Enter list of dates: " << endl;

    while( getALine( cin, tempString ) )
       {
        dateObjectI1.add( tempString );
       }

    // assign dates to other objects /////////////////////////////////////////
    dateObjectM1 = dateObjectI1;

    dateObjectQ1 = dateObjectM1;

    // display lists, unsorted ///////////////////////////////////////////////
    displayList( dateObjectI1, 'S', UNSORTED );

    displayList( dateObjectM1, 'M', UNSORTED );

    displayList( dateObjectQ1, 'Q', UNSORTED );

    // Selection sort operation //////////////////////////////////////////////
    timer.start();

    if( dateObjectI1.sort() )
       {
        timer.stop();
        timer.getElapsedTime( insTime );
        displayList( dateObjectI1, 'S', SORTED );
        iSortGood = true;
       }

    // stop timer in case of failure
    timer.stop();

    // Merge sort operation //////////////////////////////////////////////////
    timer.start();

    if( dateObjectM1.sort() )
       {
        timer.stop();
        timer.getElapsedTime( mrgTime );
        displayList( dateObjectM1, 'M', SORTED );
        mSortGood = true;
       }

    // stop timer in case of failure
    timer.stop();

    // Quick sort operation //////////////////////////////////////////////////
    timer.start();

    if( dateObjectQ1.sort() )
       {
        timer.stop();
        timer.getElapsedTime( qkTime );
        displayList( dateObjectQ1, 'Q', SORTED );
        qSortGood = true;
       }

    // stop timer in case of failure
    timer.stop();

    // Results displayed /////////////////////////////////////////////////////
    if( iSortGood )
       {
        cout << "Elapsed Time for Selection Sort: " 
             << insTime << " seconds." << endl;
       }
    else
       {
        cout << "ERROR: Failure of Selection sort due to bad input" 
             << endl << endl;
       }

    if( mSortGood )
       {
        cout << endl << "Elapsed Time for Merge Sort: " 
             << mrgTime << " seconds." << endl;
       }
    else
       {
        cout << "ERROR: Failure of merge sort due to bad input" 
             << endl << endl;
       }


    if( qSortGood )
       {
        cout << endl << "Elapsed Time for Quick Sort: " 
//.........这里部分代码省略.........
开发者ID:tbjones95,项目名称:302-Data-Structures-Project-List,代码行数:101,代码来源:PA05_Old.cpp

示例3: main


//.........这里部分代码省略.........
	const float maxeta = 5;		//maximum noise parameter
	float predNoise = 0.0;
	const int realisations = 1;	//number of realisations
	const int iterations = 2000000;	//number of time steps
	const int last = 100;			//number of last steps over which order parameter would be averaged
	int c;
	//int *gsd;						//pointer to initialise array that stores different group size 
	float timeElapsed;
	Store store(particles);			//Store class object 
	store.fileOpen();
	Swarm swarm(particles, systemSize, nPred);
	swarm.allocate();
	swarm.launchRandInit((unsigned long) t);
	SimpleTimer time; time.reset();
	time.start();
	float avgEta = 0.0;
	for (float eta = maxeta; eta <= maxeta; eta = eta + 0.2){		//loop to iterate over different noise values
		store.orientationParam = 0.0;				//initialize OP to zero before each round of replication
		for (int rep = 0; rep < realisations; rep++){		//loop to perform more number of realizations
			swarm.init(eta);
			swarm.initPredator(predNoise);
			swarm.initid();
			swarm.initAttack();
			swarm.cudaCopy();
			Screen screen;
			if (screen.init() == false){
				cout << "error initialising SDL." << endl;
			}
			for (int i = 0; i < iterations; i++){		//loop to run the simulations for number of timesteps
				screen.clear();
				swarm.update();
				const Particle * const pParticles = swarm.returnParticles();	//store the particle
				for (int p = 0; p < particles; p++){
					Particle particle = pParticles[p];
					avgEta = avgEta + particle.eta;
					}
				avgEta = avgEta / particles;
				for (int p = 0; p < particles; p++){
					Particle particle = pParticles[p];

					int x = particle.coord.x * Screen::SCREEN_WIDTH / systemSize;
					int y = particle.coord.y * Screen::SCREEN_HEIGHT / systemSize;
					//store.printCoord(x,y);
					screen.setPixel(x, y, int(255 * particle.eta / maxeta), 0, int(255 * abs(maxeta - particle.eta) / maxeta));
					}
				const Predator * const pPredators = swarm.returnPredators();
				for (int p = 0; p < nPred; p++){
					Predator predator = pPredators[p];

					int x = predator.coord.x * Screen::SCREEN_WIDTH / systemSize;
					int y = predator.coord.y * Screen::SCREEN_HEIGHT / systemSize;
					//store.printCoord(x,y);
					screen.setPixel(x, y, 0, 0, 0);
					}
				screen.update();	
				if (i >= iterations - last){
					swarm.cudaBackCopy();
					store.orientationParam += swarm.calcOrderparam();
				}
				if (screen.processEvents() == false){
					break;
				}
				if (i%10000 == 0){
					for (int p = 0; p < particles; p++){
						Particle particle = pParticles[p];
						store.eta[p] = particle.eta;
						store.print(p);
					}
					store.endl();
				}
				if (i%wait == 0) swarm.initAttack();
			}
			screen.close();
			/*if (cudaDeviceSynchronize() != cudaSuccess)
				cout << "Device synchronisation failed \n";
			swarm.cudaUniteIdBackCopy();
			swarm.grouping();
			c = swarm.findgroups();
			cout << "number of independent groups are " << c << "\n";
			gsd = new int[c];
			swarm.calcgsd(gsd);
			for (int i = 0; i < c; i++){
				store.printGroupSize(gsd[i]);
			}
			store.endl();*/	
		}
		/*store.endl();
		store.orientationParam = store.orientationParam / realisations / last;
		//cout << store.orientationParam << "\n";
		store.print(eta);
		store.endl();*/
	}
	time.stop();
	timeElapsed = time.printTime();
	store.printTime(timeElapsed);
	store.fileClose();
	
	//delete []gsd;
	return 0;
}
开发者ID:jiteshjhawar,项目名称:particleCode,代码行数:101,代码来源:main.cpp


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