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


C++ Timer::Elapsed方法代码示例

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


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

示例1: main

int main()
{
	int n_start = 25;
	int end_n = 1600;
	int n_step = 2;

	//Timer First Time is Wrong 
	timer.Start();
	Sleep(1000);
	timer.Stop();
	double t = timer.Elapsed();

	if (pick_accelerator())
	{
		cout << "This Program compare GPU and CPU performance for 'N'*'N' matrix multiplication." << endl;
		cout << endl << "______________________________________________________" << endl << "N:\tCPU Time:\tGPU Time:\t\t" << endl << "______________________________________________________" << endl;
		for (int n = n_start; n <= end_n; n *= n_step)
		{
			matrix mat1(n, n), mat2(n, n);
			mat1.random(1, 100);
			mat2.random(1, 100);

			//GPU Time Calc
			timer.Start();
			matrix mc_g = mat1.gpu_multiply<32>(&mat2);
			timer.Stop();
			double gpuTime = timer.Elapsed();

			//CPU Time Calc
			timer.Start();
			matrix mc_c = mat1.cpu_multiply(&mat2);
			timer.Stop();
			double cpuTime = timer.Elapsed();

			std::cout << n<< "\t" << cpuTime << " ms\t" << gpuTime << " ms\t" << endl << endl;
		}
	}
	getch();
	return 0;
}
开发者ID:moso94,项目名称:AMP,代码行数:40,代码来源:main.cpp

示例2: testAlgo

int testAlgo(bool (*algoFunc)(std::vector<int>&, int), std::vector<double>& prevTimes, int algoIndex, const std::vector<int>& v, int x)
{
	Timer t;

	std::vector<int> vTmp(v);
	t.Reset();
	bool res = algoFunc(vTmp, x);

	int time = t.Elapsed().count();
	// if(prevTimes[algoIndex] == 0) {
	// 	prevTimes[algoIndex] = time;
	// }

	return time;
}
开发者ID:mr-ninja-snow,项目名称:exercises,代码行数:15,代码来源:main.cpp

示例3: test2

void test2(void* scratch, uint scratchSize)
{
	StackAlloc alloc(scratch, ((u8*)scratch)+scratchSize);
	Scope a(alloc, "");
	Timer* timer = eiNewInterface(a, Timer)();
	eiInfo(AllocProfile, "########Standard List########");
	for(int itrSample = 0; itrSample < 3; itrSample++)
	{
		double begin = timer->Elapsed();
		for(int itrItr = 0; itrItr < 10; itrItr++)
		{
			std::list<int> lst;
			for(int itr = 0; itr < 50; itr++)
			{
				lst.push_front(itr);
			}
		}
		double end = timer->Elapsed();
		eiInfo(AllocProfile, "Sample %d Time: %f ms", itrSample, float(end - begin)*1000.0f);
	}

	struct ListItem
	{
		int data;
		ListItem* next;
	};

	eiInfo(AllocProfile, "########Malloc/Free########");
	for(int itrSample = 0; itrSample < 3; itrSample++)
	{
		double begin = timer->Elapsed();
		for(int itrItr = 0; itrItr < 10; itrItr++)
		{
			ListItem* lst = 0;
			for(int itr = 0; itr < 50; itr++)
			{
				ListItem* push = (ListItem*)Malloc(sizeof(ListItem));
				push->next = lst;
				push->data = itr;
				lst = push;
			}

			while(lst)
			{
				ListItem* dead = lst;
				lst = dead->next;
				Free(dead);
			}
		}
		double end = timer->Elapsed();
		eiInfo(AllocProfile, "Sample %d Time: %f ms", itrSample, float(end - begin)*1000.0f);
	}

	eiInfo(AllocProfile, "########New/Delete########");
	for(int itrSample = 0; itrSample < 3; itrSample++)
	{
		double begin = timer->Elapsed();
		for(int itrItr = 0; itrItr < 10; itrItr++)
		{
			ListItem* lst = 0;
			for(int itr = 0; itr < 50; itr++)
			{
				ListItem* push = new ListItem;
				push->next = lst;
				push->data = itr;
				lst = push;
			}

			while(lst)
			{
				ListItem* dead = lst;
				lst = dead->next;
				delete dead;
			}
		}
		double end = timer->Elapsed();
		eiInfo(AllocProfile, "Sample %d Time: %f ms", itrSample, float(end - begin)*1000.0f);
	}

	eiInfo(AllocProfile, "########Pool########");
	Pool<ListItem, false> pool(a,10000);
	for(int itrSample = 0; itrSample < 3; itrSample++)
	{
		double begin = timer->Elapsed();
		for(int itrItr = 0; itrItr < 10; itrItr++)
		{
			ListItem* lst = 0;
			for(int itr = 0; itr < 50; itr++)
			{
				ListItem* push = pool.Alloc();//(ListItem*)lca.newObject(sizeof(ListItem));
				push->next = lst;
				push->data = itr;
				lst = push;
			}

			while(lst)
			{
				ListItem* dead = lst;
				lst = dead->next;
				pool.Release(dead);//lca.deleteObject(dead);
//.........这里部分代码省略.........
开发者ID:ColinGilbert,项目名称:eighth,代码行数:101,代码来源:test_app.cpp

示例4: main


//.........这里部分代码省略.........
	}
	catch (std::exception& ex) {
		errorMessage = std::string("Error creating GraphicsEngine: ") + ex.what();
		systemLogStream.Event(errorMessage);
		logger.Flush();
	}

	if (!qcWorld) {
		return 0;
	}


	// Main rendering loop
	Timer timer;
	timer.Start();
	double frameTime = 0.05, frameRateUpdate = 0;
	std::vector<double> frameTimeHistory;
	float avgFps = 0;

	auto CaptionHandler = [&window](Vec2i cursorPos) {
		Vec2i size = window.GetSize();
		RectI rc;
		rc.top = 5;
		rc.bottom = 50;
		rc.right = size.x - 5;
		rc.left = size.x - 50;
		if (rc.IsPointInside(cursorPos))
			return eWindowCaptionButton::CLOSE;
		rc.Move({ -50, 0 });
		if (rc.IsPointInside(cursorPos))
			return eWindowCaptionButton::MAXIMIZE;
		rc.Move({ -50, 0 });
		if (rc.IsPointInside(cursorPos))
			return eWindowCaptionButton::MINIMIZE;
		if (cursorPos.y < 55) {
			return eWindowCaptionButton::BAR;
		}
		return eWindowCaptionButton::NONE;
	};
	//window.SetBorderless(true);
	//window.SetCaptionButtonHandler(CaptionHandler);

	while (!window.IsClosed()) {
		inputHandler->SetFocused(window.IsFocused());
		window.CallEvents();
		if (joyInput) {
			joyInput->CallEvents();
		}
		if (keyboardInput) {
			keyboardInput->CallEvents();
		}

		try {
			// Update world
			qcWorld->UpdateWorld(frameTime);
			qcWorld->RenderWorld(frameTime);

			// Calculate elapsed time for frame.
			frameTime = timer.Elapsed();
			timer.Reset();

			// Calculate average framerate
			frameRateUpdate += frameTime;
			if (frameRateUpdate > 0.5) {
				frameRateUpdate = 0;

				double avgFrameTime = 0.0;
				for (auto v : frameTimeHistory) {
					avgFrameTime += v;
				}
				avgFrameTime /= frameTimeHistory.size();
				avgFps = 1 / avgFrameTime;

				frameTimeHistory.clear();
			}
			frameTimeHistory.push_back(frameTime);

			// Set info text as window title
			unsigned width, height;
			engine->GetScreenSize(width, height);
			std::string title = "Graphics Engine Test | " + std::to_string(width) + "x" + std::to_string(height) + " | FPS=" + std::to_string((int)avgFps);
			window.SetTitle(title);
		}
		catch (Exception& ex) {
			std::stringstream trace;
			trace << "Graphics engine error:" << ex.what() << "\n";
			ex.PrintStackTrace(trace);
			systemLogStream.Event(trace.str());
			PostQuitMessage(0);
		}
		catch (std::exception& ex) {
			systemLogStream.Event(std::string("Graphics engine error: ") + ex.what());
			logger.Flush();
			PostQuitMessage(0);
		}
	}

	cout << "Shutting down." << endl;
	return 0;
}
开发者ID:swordlegend,项目名称:Inline-Engine,代码行数:101,代码来源:main.cpp

示例5: GameLoop

void GameLoop(HWND hwnd)
{
	render_context->ClearFrameBuffer(ARGB_BLACK);
	//************
	if (timer.Elapsed() - updateTimer > updateTick)
	{
		int          index;              // looping var
		static int   curr_texture = 7;   // currently active texture
		static int   curr_lightmap = 1;
		static float scalef = 0.5; // texture scaling factor

		// copy texture into temp display texture for rendering and scaling
		//temp_text.CopyBitmap(0, 0, textures[curr_texture], 0, 0, TEXTSIZE, TEXTSIZE);
		///////////////////////////////////////////
		// our little image processing algorithm :)
		//Cmodulated = s*C1 = (s*r1, s*g1, s*b1)
     
		////////////////////////////////////////

		// draw texture
		//temp_text.DrawBitmap24(render_context, WINDOW_WIDTH, 0);
		//DrawBottomTri(render_context, 200, 0, 100, 400, 400, 400, ARGB_RED, WINDOW_WIDTH);
		//DrawTopTri(render_context, 0, 200, 400, 200, 200, 400, ARGB_RED, WINDOW_WIDTH);
		DrawTriangle(render_context, 0, 200, 400, 250, 200, 400, ARGB_RED, WINDOW_WIDTH);
		//textures[curr_texture].DrawBitmap24(render_context, WINDOW_WIDTH, 0);
		//lightmaps[curr_lightmap].DrawBitmap24(render_context, WINDOW_WIDTH, 0);

		// test if user wants to change texture
		if (KEY_DOWN(VK_RIGHT))
		{
			if (++curr_texture > NUM_TEXT - 1)
				curr_texture = NUM_TEXT - 1;

		} // end if

		if (KEY_DOWN(VK_LEFT))
		{
			if (--curr_texture < 0)
				curr_texture = 0;

		} // end if

		// is user changing scaling factor
		if (keyboard_state[DIK_UP])
		{
			scalef += .01;
			if (scalef > 10)
				scalef = 10;
		} // end if

		if (keyboard_state[DIK_DOWN])
		{
			scalef -= .01;
			if (scalef < 0)
				scalef = 0;
		} // end if

		/*	
		for (int x = 0; x < bitmap24bit.bitmapinfoheader.biWidth; x++)
		{
			for (int y = 0; y < bitmap24bit.bitmapinfoheader.biHeight; y++)
			{
				unsigned char B = *(bitmap24bit.buffer + y * 640 * 3 + x * 3 + 0);
				unsigned char G = *(bitmap24bit.buffer + y * 640 * 3 + x * 3 + 1);
				unsigned char R = *(bitmap24bit.buffer + y * 640 * 3 + x * 3 + 2);

				render_context->frame_buffer[x + y * 640] = ARGB(0, (int)R, (int)G, (int)B);
			}
		}
		*/

		window_hdc = GetDC(hwnd);
		SelectObject(buffer_hdc, now_bitmap);
		BitBlt(window_hdc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, buffer_hdc, 0, 0, SRCCOPY);
		ReleaseDC(hwnd, window_hdc);
	}
	frames++;
	if (timer.Elapsed() - elapsed > 1.0f)
	{
		elapsed += 1.0f;
		cout << frames << "fps" << endl;
		frames = 0;
	}
	// **************
}
开发者ID:fxyyoung,项目名称:TinyRenderer,代码行数:85,代码来源:main.cpp

示例6: GameLoop

void GameLoop(HWND hwnd)
{
	render_context->ClearFrameBuffer();

	static Mat4f mrot; // general rotation matrix
	static float x_ang = 0.0f, y_ang = 0.2f, z_ang = 0.0f;

	//每秒执行60次部分
	if (timer.Elapsed() - updateTimer > updateTick)
	{
		updateTimer = updateTimer + updateTick;
		// reset angles
		//x_ang = 0.0f;
		if (KEY_DOWN(VK_UP))
			obj.world_pos.z = obj.world_pos.z - 0.5f;
		if (KEY_DOWN(VK_DOWN))
			obj.world_pos.z = obj.world_pos.z + 0.5f;
		/*if (KEY_DOWN(VK_LEFT))
			x_ang = 0.2f;
		if (KEY_DOWN(VK_RIGHT))
			x_ang = -0.2f;*/
		
	}

	//尽快执行部分
	{
		// 重设剔除、裁剪、隐面标志位
		obj.Reset();

		// 产生绕三轴旋转矩阵
		mrot = Mat4f::Rotation(x_ang, y_ang, z_ang);

		// 直接对局部坐标变换,存入局部坐标
		obj.Transform(mrot, TRANSFORM_LOCAL_ONLY, 1);

		// 模型坐标到世界坐标变换
		obj.ModelToWorld();

		// 建立相机变换矩阵,此例中一般为单位矩阵
		//cam.BuildMatrixEuler(CAM_ROT_SEQ_ZYX);

		// 执行隐面剔除
		obj.RemoveBackFaces(cam);

		// 世界坐标到相机坐标变换
		obj.WorldToCamera(cam);

		//获得三角形的法向量
		obj.GetTriangleNormal();

		// 相机坐标投影变换
		obj.CameraToPerspective(cam);

		obj.ClipUDLR();

		// 投影坐标到屏幕坐标
		obj.PerspectiveToScreen(cam);

		// 光照纹理方式绘制
		obj.DrawPlane(render_context, WINDOW_WIDTH);
		
		window_hdc = GetDC(hwnd);
		SelectObject(buffer_hdc, now_bitmap);
		BitBlt(window_hdc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, buffer_hdc, 0, 0, SRCCOPY);
		ReleaseDC(hwnd, window_hdc);
	}

	//每秒执行1次部分
	frames++;
	if (timer.Elapsed() - elapsed > 1.0f)
	{
		elapsed += 1.0f;
		cout << frames << "fps" << endl;
		frames = 0;
	}

}
开发者ID:fxyyoung,项目名称:SoftRender,代码行数:77,代码来源:main.cpp


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