예제 #1
0
int main()
{
    Stopwatch stopwatch;
    HANDLE hTimer = NULL;

    // Create an unnamed waitable timer.
    hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
    if (NULL == hTimer) {
        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
        return 1;
    }

    // With Sleep
    stopwatch.Start();
    DoWait(hTimer, 1000);
    printf("Wait 1000ms, Elapsed time : %d\n", stopwatch.ElapsedTime());

    // With Sleep
    stopwatch.Start();
    DoWait(hTimer, 1234);
    Sleep(100);
    printf("Wait 1234ms with Sleep(100), Elapsed time : %d\n", stopwatch.ElapsedTime());

    return 0;
}
예제 #2
0
//------------------------------------------------------------------------------
static void
display() {

    Stopwatch s;
    s.Start();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0, 0, g_width, g_height);
    g_hud.FillBackground();

    double aspect = g_width/(double)g_height;
    identity(g_transformData.ModelViewMatrix);
    translate(g_transformData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
    rotate(g_transformData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
    rotate(g_transformData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
    rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
    translate(g_transformData.ModelViewMatrix,
              -g_center[0], -g_center[1], -g_center[2]);
    perspective(g_transformData.ProjectionMatrix,
                45.0f, (float)aspect, 0.01f, 500.0f);
    multMatrix(g_transformData.ModelViewProjectionMatrix,
               g_transformData.ModelViewMatrix,
               g_transformData.ProjectionMatrix);

    glEnable(GL_DEPTH_TEST);

    drawStencils();

    // draw the control mesh
    g_controlMeshDisplay.Draw(g_stencilOutput->BindSrcBuffer(), 3*sizeof(float),
                              g_transformData.ModelViewProjectionMatrix);

    s.Stop();
    float drawCpuTime = float(s.GetElapsed() * 1000.0f);
    s.Start();
    glFinish();
    s.Stop();
    float drawGpuTime = float(s.GetElapsed() * 1000.0f);

    if (g_hud.IsVisible()) {
        g_fpsTimer.Stop();
        double fps = 1.0/g_fpsTimer.GetElapsed();
        g_fpsTimer.Start();

        g_hud.DrawString(10, -100,  "# stencils   : %d", g_nsamplesDrawn);
        g_hud.DrawString(10, -80,  "EvalStencils : %.3f ms", g_evalTime);
        g_hud.DrawString(10, -60,  "GPU Draw     : %.3f ms", drawGpuTime);
        g_hud.DrawString(10, -40,  "CPU Draw     : %.3f ms", drawCpuTime);
        g_hud.DrawString(10, -20,  "FPS          : %3.1f", fps);

        g_hud.Flush();
    }
    glFinish();

    //checkGLErrors("display leave");
}
예제 #3
0
//------------------------------------------------------------------------------
void
updateGeom() {

    int nverts = (int)g_orgPositions.size() / 3;

    std::vector<float> vertex;
    vertex.reserve(nverts*6);

    const float *p = &g_orgPositions[0];
    const float *n = &g_normals[0];

    float r = sin(g_frame*0.001f) * g_moveScale;
    for (int i = 0; i < nverts; ++i) {
        float move = 0.05f*cosf(p[0]*20+g_frame*0.01f);
        float ct = cos(p[2] * r);
        float st = sin(p[2] * r);
        g_positions[i*3+0] = p[0]*ct + p[1]*st;
        g_positions[i*3+1] = -p[0]*st + p[1]*ct;
        g_positions[i*3+2] = p[2];
        
        p += 3;
    }

    p = &g_positions[0];
    for (int i = 0; i < nverts; ++i) {
        vertex.push_back(p[0]);
        vertex.push_back(p[1]);
        vertex.push_back(p[2]);
        vertex.push_back(n[0]);
        vertex.push_back(n[1]);
        vertex.push_back(n[2]);
        
        p += 3;
        n += 3;
    }

    if (!g_vertexBuffer)
        g_vertexBuffer = g_osdmesh->InitializeVertexBuffer(6);
    g_vertexBuffer->UpdateData(&vertex[0], nverts);

    Stopwatch s;
    s.Start();

    g_osdmesh->Subdivide(g_vertexBuffer, NULL);

    s.Stop();
    g_cpuTime = float(s.GetElapsed() * 1000.0f);
    s.Start();
    g_osdmesh->Synchronize();
    s.Stop();
    g_gpuTime = float(s.GetElapsed() * 1000.0f);

    glBindBuffer(GL_ARRAY_BUFFER, g_vertexBuffer->GetGpuBuffer());
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
예제 #4
0
int main(int argc, char* argv[])
{
	LinearEquationSystemFactory factory;
	LinearEquationSystemSolver solver;

	for (; n <= nLimit; n *= multiplier)
	{
		float minTime = FLT_MAX;
		for (int attempt = 0; attempt < repeatsNumber; ++attempt)
		{
			LinearEquationSystem* system = factory.Create(n);
			NUMBER* solution = new NUMBER[n];

			stopwatch.Start();			
			solver.Solve(system, solution);
			stopwatch.Stop();

			float elapsedSeconds = stopwatch.GetElapsedSeconds();
			if (elapsedSeconds < minTime)
			{
				minTime = elapsedSeconds;
			}

			bool result = checker.IsCorrectSolution(system, solution);
			printf("Correct: %s \n", result ? "yes" : "no");

			delete system;
			delete []solution;
		}

		printf("N = %d, Elapsed seconds: %f\n", n, minTime);
	}
}
예제 #5
0
static void do_parallel_map(Stopwatch& sw) {
  // Create a bunch of subcontexts from here and put them in a map
  auto all = create();
  ::ContextMap<size_t> mp;
  for (size_t i = N; i < all.size(); i++)
    mp.Add(i, all[i]);

  // Now the threads that will make progress hard:
  auto proceed = std::make_shared<bool>(true);
  for (size_t i = N; i--;)
    std::thread([proceed, mp] {
      while (*proceed)
        for (const auto& cur : mp)
          ;
    }).detach();
  auto cleanup = MakeAtExit([&] { *proceed = false; });

  std::this_thread::sleep_for(std::chrono::milliseconds(100));

  // Enumerate the map while iteration is underway
  sw.Start();
  for (auto& cur : mp)
    ;
  sw.Stop(n);
}
__attribute__((noinline)) void benchNavigatorNoReloc(VNavigator const *se, SOA3D<Precision> const &points,
                                                     SOA3D<Precision> const &dirs, NavStatePool const &inpool,
                                                     NavStatePool &outpool)
{
  Precision *steps = new Precision[points.size()];
  Precision *safeties;
  if (WithSafety) safeties = new Precision[points.size()];
  Stopwatch timer;
  size_t hittargetchecksum = 0L;
  timer.Start();
  for (decltype(points.size()) i = 0; i < points.size(); ++i) {
    if (WithSafety) {
      steps[i] = se->ComputeStepAndSafety(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], true, safeties[i]);
    } else {
      steps[i] = se->ComputeStep(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], *outpool[i]);
    }
  }
  timer.Stop();
  std::cerr << timer.Elapsed() << "\n";
  double accum(0.), saccum(0.);
  for (decltype(points.size()) i = 0; i < points.size(); ++i) {
    accum += steps[i];
    if (WithSafety) {
      saccum += safeties[i];
    }
    if (outpool[i]->Top()) hittargetchecksum += (size_t)outpool[i]->Top()->id();
  }
  delete[] steps;
  std::cerr << "accum  " << se->GetName() << " " << accum << " target checksum " << hittargetchecksum << "\n";
  if (WithSafety) {
    std::cerr << "saccum  " << se->GetName() << " " << saccum << "\n";
  }
}
예제 #7
0
static void
updateGeom() {

    int nverts = (int)g_orgPositions.size() / 3;

    const float *p = &g_orgPositions[0];

    float r = sin(g_frame*0.001f) * g_moveScale;

    g_positions.resize(nverts*3);

    for (int i = 0; i < nverts; ++i) {
        //float move = 0.05f*cosf(p[0]*20+g_frame*0.01f);
        float ct = cos(p[2] * r);
        float st = sin(p[2] * r);
        g_positions[i*3+0] = p[0]*ct + p[1]*st;
        g_positions[i*3+1] = -p[0]*st + p[1]*ct;
        g_positions[i*3+2] = p[2];
        p+=3;
    }

    Stopwatch s;
    s.Start();

    // update control points
    g_stencilOutput->UpdateData(&g_positions[0], 0, nverts);

    // Update random points by applying point & tangent stencils
    g_stencilOutput->EvalStencils();


    s.Stop();
    g_evalTime = float(s.GetElapsed() * 1000.0f);
}
예제 #8
0
파일: main.cpp 프로젝트: ThePhD/hya
int main ( ) {
	using namespace Furrovine;
	using namespace Furrovine::Audio;
	using namespace Furrovine::Pipeline;
	//using namespace Furrovine::Graphics;

	const static uint32 samplerate = 48000;
	const static uint32 bitspersample = 16;
	const static uint32 channelcount = 2;

	PCMAudioData data = WavAudioLoader( )( "16bit.wav" );

	AudioDevice baseaudiodevice( bitspersample, channelcount, samplerate );
	RealtimeAudioDevice audiodevice( baseaudiodevice, milliseconds( 10 ) );
	audiodevice.AddDSP( PerChannelDelay( audiodevice.PCMDescription( ), { seconds( 0.513 ), seconds( 0.490 ) }, real( 0.25 ) ) );
	
	AudioBuffer buffer( data.Buffer(), 0, 0, 0, 0, 1 );
	audiodevice.SubmitBuffer( buffer );

	Stopwatch stopwatch;
	stopwatch.Start( );
	while ( true ) {
		double seconds = stopwatch.ElapsedSeconds( );
		
		if ( seconds < 1 )
			continue;

		//audiodevice.SubmitBuffer( buffer );
		stopwatch.Restart( );
	}

}
예제 #9
0
int benchNoCachingNoVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
                           std::vector<Vector3D<Precision>> const &corners
#ifdef SORTHITBOXES
                           ,
                           Container_t &hitlist
#endif
                           )
{
#ifdef INNERTIMER
  Stopwatch timer;
  timer.Start();
#endif
  int vecsize  = corners.size() / 2;
  int hitcount = 0;
  for (auto box = 0; box < vecsize; ++box) {
    double distance = BoxImplementation<translation::kIdentity, rotation::kIdentity>::Intersect(
        &corners[2 * box], point, dir, 0, vecgeom::kInfLength);
    if (distance < vecgeom::kInfLength) {
      hitcount++;
#ifdef SORTHITBOXES
      hitlist.push_back(BoxIdDistancePair_t(box, distance));
#endif
    }
  }
#ifdef INNERTIMER
  timer.Stop();
  std::cerr << "# ORDINARY hitting " << hitcount << "\n";
  std::cerr << "# ORDINARY timer " << timer.Elapsed() << "\n";
#endif
  return hitcount;
}
//-------------------------------------------------------------------------------------------------
void Benchmark::DoAll(std::vector<string> vExpr, long num)
{
   printf("\n\n\n");

   PreprocessExpr(vExpr);

   char outstr[400], file[400];
   time_t t = time(NULL);

   #ifdef _DEBUG
   sprintf(outstr, "Bench_%s_%%Y%%m%%d_%%H%%M%%S_dbg.txt", GetShortName().c_str());
   #else
   sprintf(outstr, "Bench_%s_%%Y%%m%%d_%%H%%M%%S_rel.txt", GetShortName().c_str());
   #endif

   strftime(file, sizeof(file), outstr, localtime(&t));

   FILE *pRes = fopen(file, "w");
   assert(pRes);

   fprintf(pRes,  "# Benchmark results\n");
   fprintf(pRes,  "#   Parser:  %s\n", GetName().c_str());
   fprintf(pRes,  "#   Evals per expr:  %ld\n", num);
   fprintf(pRes,  "#\"ms per eval [ms]\", \"evals per sec\", \"Result\", \"expr_len\", \"Expression\"\n");

   std::string sExpr;

   Stopwatch timer;
   timer.Start();
   for (std::size_t i = 0; i < vExpr.size(); ++i)
   {
      try
      {
         DoBenchmark(vExpr[i], num);
         fprintf(pRes, "%4.6lf, %4.6lf, %4.6lf, %d, %s, %s\n", m_fTime1, 1000.0/m_fTime1, m_fResult, (int)vExpr[i].length(), vExpr[i].c_str(), m_sInfo.c_str());
         printf(       "%4.6lf, %4.6lf, %4.6lf, %d, %s, %s\n", m_fTime1, 1000.0/m_fTime1, m_fResult, (int)vExpr[i].length(), vExpr[i].c_str(), m_sInfo.c_str());
      }
      catch(...)
      {
         fprintf(pRes, "fail: %s\n", vExpr[i].c_str());
         printf(       "fail: %s\n", vExpr[i].c_str());
      }

      fflush(pRes);
   }
   double dt = timer.Stop() / ((double)vExpr.size() * num);

   fprintf(pRes,  "# avg. time per expr.: %lf ms;  avg. eval per sec: %lf; total bytecode size: %d",
           dt,
           1000.0 / dt,
           m_nTotalBytecodeSize);

   printf("\n#\n# avg. time per expr.: %lf ms;  avg. eval per sec: %lf; total bytecode size: %d",
          dt,
          1000.0 / dt,
          m_nTotalBytecodeSize);

   fclose(pRes);
}
예제 #11
0
	void playback_exact_CSpace_R3()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readObjFile(P, "../data/models/CupSpoon/Cup.obj");
		readObjFile(Q, "../data/models/CupSpoon/Spoon.obj");

		P->ComputeRadius();
		Q->ComputeRadius();

		Collider3D collider(P, Q);

		C2A_Model* CSpace;
		readObjFile(CSpace, "../data/cupspoon.obj");

		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		std::ofstream timing_file("timing_exact_R3.txt");
		std::ofstream PD_file("PD_exact_R3.txt");

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];


			boost::timer t;
			//aTimer.Reset();
			aTimer.Start();
			std::pair<DataVector, double> pd_result;
			if(!collider.isCollide(q_col)) 
			{
				pd_result.second = 0;
			}
			else
			{
				pd_result = Minkowski_Cspace_3D::Exact_PD_R3(q, CSpace);
			}
			aTimer.Stop();
			PD_file << pd_result.second << " ";	
			//timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
예제 #12
0
double
OsdMesh::Synchronize() {

    Stopwatch s;
    s.Start();
    {
        _dispatcher->Synchronize();
    }
    s.Stop();

    return s.GetElapsed();
}
예제 #13
0
void Benchmark::Integer8_Test()
{
    double Score   ( 0 ),
           Cur_Time( 0 );
    uint32_t loops ( 0 );
    Stopwatch watch;
	
    watch.Start();
    for( ; Cur_Time < Time_Per_Test; ++loops, watch.Look( Cur_Time ), Status_Done( static_cast< uint32_t >( Status_Mul*Cur_Time  ))  )
        Score += Intern_Integer8_Test();
	  
    m_Integer8_Score = static_cast< uint32_t >(Score/loops);
}
예제 #14
0
void Benchmark::Integer16_Test()
{
	double tmp(0);
	double Cur_Time(0);
	uint32_t loops=0;
	Stopwatch watch;
	
	watch.Start();
	for( ; Cur_Time < Time_Per_Test; ++loops, watch.Look( Cur_Time ), Status_Done( static_cast< uint32_t >( Status_Mul*Cur_Time  ))  )
	    tmp += Intern_Integer16_Test();
	  
	m_Integer16_Score = static_cast< uint32_t >(tmp/loops);
}
예제 #15
0
void Benchmark::Fp128_Test()
{
	if( sizeof( long double ) != 16 )  
	    return;
	double tmp(0);
	double Cur_Time(0);
	uint32_t loops=0;
	Stopwatch watch;
	
	
	watch.Start();
	for( ; Cur_Time < Time_Per_Test; ++loops, watch.Look( Cur_Time ), Status_Done( static_cast< uint32_t >( Status_Mul*Cur_Time  ))  )
	    tmp += Intern_Fp128_Test();
	
	m_Fp128_Score = static_cast< uint32_t >(tmp/loops);
}
void Test1()
{
    DIVIDING_LINE_1('-');

    constexpr int Count = 2001001;

#if HAS_BOOST
    boost::recursive_mutex osMutex;
    ostream_t os(std::cout, osMutex);
#else
    ostream_t &os = std::cout;
#endif

    Stopwatch sw;
    sw.Start();

    ProducerConsumerContext context(os, Count, Count / 10, ENABLE_LOGGING);

    Producer p1(context, 0, Count / 2, 200);
    Producer p2(context, Count / 2, Count - Count / 2, 200);

    Consumer c1(context, Count / 3, 200);
    Consumer c2(context, Count / 3, 200);
    Consumer c3(context, Count - Count / 3 - Count / 3, 200);

    std::vector<std::thread> threads;
    threads.push_back(p1.Create());
    threads.push_back(p2.Create());
    threads.push_back(c1.Create());
    threads.push_back(c2.Create());
    threads.push_back(c3.Create());

    for (auto &t : threads)
        t.join();

    sw.Stop();
    std::cout << "Ellapsed time: " << sw.GetElapsedMilliseconds() << "ms" << std::endl;

    std::cout << "Checking if test is passed...\n";

    sw.Restart();
    bool ok = context.IsTestPassed();
    sw.Stop();

    std::cout << "It takes " << sw.GetElapsedMilliseconds() << "ms to figure out if test is passed." << std::endl;
    std::cout << "Is test passed? " << std::boolalpha << ok << std::endl;
}
int main()
{
    // Stopwatch object used to measure time intervals
    Stopwatch sw;   

    // Record start time
    sw.Start();
    
    // Portion of code to be timed
    ::Sleep(1000);  // Just wait for 1,000 ms (1 second)
    
    // Record end time
    sw.Stop();

    // Print timing results
    cout << "Elapsed time: " << sw.ElapsedMilliseconds() << " ms\n";
}
void StorageDeleteFileChunkJob::Execute()
{
    Stopwatch   sw;
    Buffer      filename;
    
    Log_Message("Deleting file chunk %U from disk", chunk->GetChunkID());
    sw.Start();
    
    filename.Write(chunk->GetFilename());
    delete chunk;
    chunk = NULL;

    StorageFileDeleter::Delete(filename.GetBuffer());

    sw.Stop();
    Log_Debug("Deleted, elapsed: %U", (uint64_t) sw.Elapsed());
}
void Test0()
{
    DIVIDING_LINE_1('-');

#if !PRODUCER_DO_MY_BEST && !CONSUMER_DO_MY_BEST
# error You are in danger of deadlock!
#endif

    constexpr int Count = 2000;

#if HAS_BOOST
    boost::recursive_mutex osMutex;
    ostream_t os(std::cout, osMutex);
#else
    ostream_t &os = std::cout;
#endif

    Stopwatch sw;
    sw.Start();

    ProducerConsumerContext context(os, Count, Count / 10, ENABLE_LOGGING);

    Producer p1(context, 0, Count / 2, 200);
    Producer p2(context, Count / 2, Count - Count / 2, 200);

    Consumer c1(context, Count / 3, 200);
    Consumer c2(context, Count / 3, 200);
    Consumer c3(context, Count - Count / 3 - Count / 3, 200);

    std::vector<std::thread> threads;
    threads.push_back(p1.Create());
    threads.push_back(p2.Create());
    threads.push_back(c1.Create());
    threads.push_back(c2.Create());
    threads.push_back(c3.Create());

    for (auto &t : threads)
        t.join();

    sw.Stop();

    std::cout << "Test Done: " << context.IsTestPassed() << ". Ellapsed time: " << sw.GetElapsedMilliseconds() << "ms\n";
}
예제 #20
0
double
OsdMesh::Subdivide(OsdVertexBuffer *vertex, OsdVertexBuffer *varying) {

    _dispatcher->BindVertexBuffer(vertex, varying);

    Stopwatch s;
    s.Start();
    {
        _dispatcher->OnKernelLaunch();

        _farMesh->Subdivide(_level+1, _exact);

        _dispatcher->OnKernelFinish();
    }
    s.Stop();

    _dispatcher->UnbindVertexBuffer();

    return s.GetElapsed();
}
예제 #21
0
	void playback_local_PD_R3()
	{
		std::ofstream timing_file("timing_local_PD_R3.txt");
		std::ofstream PD_file("PD_local_R3.txt");

		std::vector<C2A_Model*> P;
		std::vector<C2A_Model*> Q;

		readObjFiles(P, "../data/models/CupSpoon/cup_convex.obj");
		readObjFiles(Q, "../data/models/CupSpoon/spoon_convex.obj");


		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];

			boost::timer t;
			aTimer.Reset();
			aTimer.Start();
			double pd = Collider3D::PDt(P, Q, q_col);
			PD_file << pd << " ";	
			// timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
예제 #22
0
static void do_parallel_enum(Stopwatch& sw) {
  AutoCurrentContext ctxt;
  auto all = create();

  // Create threads which will cause contention:
  auto proceed = std::make_shared<bool>(true);
  for (size_t nParallel = N; nParallel--;) {
    std::thread([proceed, all, ctxt] {
      while (*proceed)
        for (auto cur : ContextEnumerator(ctxt))
          ;
    }).detach();
  }
  auto cleanup = MakeAtExit([&] { *proceed = false; });

  std::this_thread::sleep_for(std::chrono::milliseconds(100));

  // Perform parallel enumeration
  sw.Start();
  for (auto cur : ContextEnumerator(ctxt))
    ;
  sw.Stop(n);
}
예제 #23
0
Benchmark::Test_Re_Type Benchmark::Memory_DA_Test()
{
    Stopwatch watch;
    double Comp_Time(0);
  
    if( !::Force_No_Threads )
    {
	bool Blocker( true );
        
	Smart_Array_Pointer< ThreadHandle > Thread_Mem( Thread_Number );
	if( !Thread_Mem )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
        ThreadHandle* Threads = Thread_Mem.Get_Mem();

	uint8_t i( 0 );
	
	Smart_Array_Pointer< Little_Thread_Helper > Thread_Helper_Mem( Thread_Number );
	if( !Thread_Helper_Mem )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	Little_Thread_Helper* Thread_Helpers = Thread_Helper_Mem.Get_Mem();
	for( ; i < Thread_Number; ++i )
	    Thread_Helpers[i].m_Blocker = &Blocker; //That isn't that nice...but needed
	        
	
	for( i=0; i < Thread_Number; ++i )
	     ThreadCreate( Threads[i], Memory_DA_Test_Thread<Buf_Size,Loops>, &Thread_Helpers[i]  );


	//Now it's starts!
	const double Start_Time = Stopwatch::Get_Time();
	Blocker = false;
	ThreadWaitFor( Threads, Thread_Number );
	
	if( m_Error )
	    return 0;
	for( i=0; i < Thread_Number; ++i )
	    if( Comp_Time < Thread_Helpers[i].m_Needed_Time - Start_Time )
	        Comp_Time = Thread_Helpers[i].m_Needed_Time - Start_Time;
	
	
	return ((Loops*Thread_Number) / Comp_Time)/1000;
    }
    else
    {
	watch.Start();
	
	if( !Intern_Mem_DA_Test< Buf_Size, Loops > () )
	{
	    m_Error = Benchmark::Mem_Alloc; 
	    return 0;
	}

	watch.Stop( &Comp_Time );
	return (Loops / Comp_Time)/1000;
    }
}
예제 #24
0
Benchmark::Test_Re_Type Benchmark::Calculation_Test()
{
    Stopwatch watch;
    double Comp_Time(0);
    
    if( !::Force_No_Threads )
    {
	bool Blocker( true );
        
	Smart_Array_Pointer< ThreadHandle > Threads_Mem( Thread_Number );
	if( !Threads_Mem )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	ThreadHandle* Threads = Threads_Mem.Get_Mem();

	    uint8_t i( 0 );
	
	    //Preallocates us the memory needed..
	    Smart_Array_Pointer< Thread_Helper< Type, Loops > > Thread_Helpers_Mem( Thread_Number );
	    if( !Thread_Helpers_Mem )
	    {
		m_Error = Mem_Alloc;
		return 0;
	    } 
	    Thread_Helper< Type, Loops >* Thread_Helpers = Thread_Helpers_Mem.Get_Mem();
	    for( ; i < Thread_Number; ++i )
		 Thread_Helpers[i].m_Blocker = &Blocker; //That isn't that nice...but needed
	        
	
	    for( i=0; i < Thread_Number; ++i )
		ThreadCreate( Threads[i], Calculation_Test_Thread< Type, Loops >, &Thread_Helpers[i] );

	    //Now it's starts!
	    //Maybe we should wait a moment, so every
	    //watch.Start();
	    const double Start_Time = Stopwatch::Get_Time();
	    Blocker = false;
	    ThreadWaitFor( Threads, Thread_Number );
	    
	    for( i=0; i < Thread_Number; ++i )
		if( Comp_Time < Thread_Helpers[i].m_Needed_Time - Start_Time )
		    Comp_Time = Thread_Helpers[i].m_Needed_Time - Start_Time;
		
	
	    double Score = static_cast< double > (  ((Loops-1)*(Loops-1)*Thread_Number) / Comp_Time);
	    return Score / 1000; //A little score modi :)
	}
	else
	{ 
	    Smart_Array_Pointer< Type > Buffer_Mem( Loops );
	    if( !Buffer_Mem )
	    {
		m_Error = Mem_Alloc;
		return 0;
	    }
	    Type* Buffer = Buffer_Mem.Get_Mem(); //Does we need some extra to prevent for buffer over/under flows?
	
	    watch.Start();
	    Intern_Calculation_Test< Type, Loops-1 > ( Buffer );
	    watch.Stop( &Comp_Time );
	
	
	    double Score = static_cast< double > (  ((Loops-1)*(Loops-1)) / Comp_Time);
	    return Score / 1000; //Little score modi!
	}
}
예제 #25
0
Benchmark::Test_Re_Type Benchmark::Memory_RW_Test()
{
    Stopwatch watch;
    double Comp_Time( 0 );
    static const uint32_t Half_Buf_Size( Buf_Size>>1 );
	
    if( !::Force_No_Threads )
    {
	bool Blocker( true );
        
	Smart_Array_Pointer< ThreadHandle > Thread_Mem( Thread_Number );
	if( !Thread_Mem )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	
        ThreadHandle* Threads = Thread_Mem;

	uint8_t i( 0 );
	
	
	Smart_Array_Pointer< Thread_Helper< uint8_t, Buf_Size > > Thread_Helper_Mem( Thread_Number );
	if( !Thread_Helper_Mem  || !Thread_Helper_Mem.Get_Mem()->m_Mem.Is_Allocated()  ) //uah...evil line :x
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	Thread_Helper< uint8_t, Buf_Size >* Thread_Helpers = Thread_Helper_Mem.Get_Mem();
	for( ; i < Thread_Number; ++i )
	    Thread_Helpers[i].m_Blocker = &Blocker; //That isn't that nice...but needed
	        
	
	for( i=0; i < Thread_Number; ++i )
	    ThreadCreate( Threads[i], Memory_RW_Test_Thread< Half_Buf_Size, Loops >, &Thread_Helpers[i] );


	//Now it's starts!
	//Maybe we should wait a moment, so every
	//watch.Start();
	const double Start_Time = Stopwatch::Get_Time();
	Blocker = false;
	ThreadWaitFor( Threads, Thread_Number );
	
	//watch.Stop( &Comp_Time );
	for( i=0; i < Thread_Number; ++i )
	    if( Comp_Time < Thread_Helpers[i].m_Needed_Time - Start_Time )
	        Comp_Time = Thread_Helpers[i].m_Needed_Time - Start_Time;
	
	
	return ((Loops*Thread_Number) / Comp_Time)/1000;
    }
    else
    {	
	Smart_Array_Pointer< uint8_t > a( Half_Buf_Size );
	Smart_Array_Pointer< uint8_t > b( Half_Buf_Size );
	if( !a  ||  !b )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	
	watch.Start();
	Intern_Memory_RW_Test< Half_Buf_Size, Loops > ( a.Get_Mem(), b.Get_Mem() );
	watch.Stop( &Comp_Time );
		
	
	return (Loops / Comp_Time)/1000;
    }
}
예제 #26
0
파일: viewer.cpp 프로젝트: Len3d/OpenSubdiv
//------------------------------------------------------------------------------
int main(int argc, char ** argv)
{
    bool fullscreen = false;
    std::string str;
    for (int i = 1; i < argc; ++i) {
        if (!strcmp(argv[i], "-d"))
            g_level = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-c"))
            g_repeatCount = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-f"))
            fullscreen = true;
        else {
            std::ifstream ifs(argv[1]);
            if (ifs) {
                std::stringstream ss;
                ss << ifs.rdbuf();
                ifs.close();
                str = ss.str();
                g_defaultShapes.push_back(SimpleShape(str.c_str(), argv[1], kCatmark));
            }
        }
    }
    initializeShapes();
    OsdSetErrorCallback(callbackError);

    if (not glfwInit()) {
        printf("Failed to initialize GLFW\n");
        return 1;
    }

    static const char windowTitle[] = "OpenSubdiv glBatchViewer";
    
#define CORE_PROFILE
#ifdef CORE_PROFILE
    setGLCoreProfile();
#endif

#if GLFW_VERSION_MAJOR>=3
    if (fullscreen) {
    
        g_primary = glfwGetPrimaryMonitor();

        // apparently glfwGetPrimaryMonitor fails under linux : if no primary,
        // settle for the first one in the list    
        if (not g_primary) {
            int count=0;
            GLFWmonitor ** monitors = glfwGetMonitors(&count);

            if (count)
                g_primary = monitors[0];
        }
        
        if (g_primary) {
            GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
            g_width = vidmode->width;
            g_height = vidmode->height;
        }
    }

    if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, 
                                       fullscreen and g_primary ? g_primary : NULL, NULL))) {
        printf("Failed to open window.\n");
        glfwTerminate();
        return 1;
    }
    glfwMakeContextCurrent(g_window);
    glfwSetKeyCallback(g_window, keyboard);
    glfwSetCursorPosCallback(g_window, motion);
    glfwSetMouseButtonCallback(g_window, mouse);
    glfwSetWindowSizeCallback(g_window, reshape);
#else
    if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8,
                       fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) {
        printf("Failed to open window.\n");
        glfwTerminate();
        return 1;
    }
    glfwSetWindowTitle(windowTitle);
    glfwSetKeyCallback(keyboard);
    glfwSetMousePosCallback(motion);
    glfwSetMouseButtonCallback(mouse);
    glfwSetWindowSizeCallback(reshape);
#endif

#if defined(OSD_USES_GLEW)
#ifdef CORE_PROFILE
    // this is the only way to initialize glew correctly under core profile context.
    glewExperimental = true;
#endif
    if (GLenum r = glewInit() != GLEW_OK) {
        printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
        exit(1);
    }
#ifdef CORE_PROFILE
    // clear GL errors which was generated during glewInit()
    glGetError();
#endif
#endif

    // activate feature adaptive tessellation if OSD supports it
    g_adaptive = OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation();

    initGL();

    glfwSwapInterval(0);

    initHUD();
    callbackModel(g_currentShape);

    g_fpsTimer.Start();
    while (g_running) {
        idle();
        display();
        
#if GLFW_VERSION_MAJOR>=3
        glfwPollEvents();
        glfwSwapBuffers(g_window);
#else
        glfwSwapBuffers();
#endif
    }

    uninitGL();
    glfwTerminate();
}
예제 #27
0
Benchmark::Test_Re_Type Benchmark::MultiT_MLuL_Test()
{
    Stopwatch watch;
    double Comp_Time( 0 );

    if( !::Force_No_Threads )
    {
	bool Blocker( true );
	uint8_t i( 0 );

	Smart_Array_Pointer< ThreadHandle > Thread_Mem( Thread_Number );
	ThreadHandle*const Threads = Thread_Mem.Get_Mem();
    #if IsLin
	Smart_Array_Pointer< Little_Mutex_Helper > Mutex_Mem( Thread_Number );
	if( !Thread_Mem.Is_Allocated()   ||   !Mutex_Mem.Is_Allocated()  )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	Little_Mutex_Helper*const Mutex = Mutex_Mem.Get_Mem();
	
    #elif IsWin
    	Smart_Array_Pointer< CRITICAL_SECTION > CS_Mem( Thread_Number );
        CRITICAL_SECTION*const CS = CS_Mem.Get_Mem();
	for( ; i < Thread_Number; ++i )
	    InitializeCriticalSection( &CS[i] );
    #endif
	
	//Preallocates us the memory needed...
	Smart_Array_Pointer< Special_Thread_Helper > Thread_Helpers_Mem( Thread_Number );
	if( !Thread_Helpers_Mem )
	{
	    m_Error = Mem_Alloc;
	    return 0;
	}
	Special_Thread_Helper* Thread_Helpers = Thread_Helpers_Mem.Get_Mem();
	
	for( i =0; i < Thread_Number; ++i )
	{
	    Thread_Helpers[i].m_Blocker = &Blocker; //That isn't that nice...but needed
	    Thread_Helpers[i].m_Mutex =
	    #if IsLin
	        &Mutex[i].m_Mutex
	    #elif IsWin
		&CS[i]
	    #endif
		;
	}
	        
	
	for( i=0; i < Thread_Number; ++i )
	    ThreadCreate( Threads[i], MultiT_MLuL_Test_Thread< Loops >, &Thread_Helpers[i] );


	//Now it's starts!
	//Maybe we should wait a moment, so every
	double Start_Time = Stopwatch::Get_Time();
	Blocker = false;
	ThreadWaitFor( Threads, Thread_Number );

	for( i=0; i < Thread_Number; ++i )
	    if( Comp_Time < Thread_Helpers[i].m_Needed_Time - Start_Time )
	        Comp_Time = Thread_Helpers[i].m_Needed_Time - Start_Time;
	
	
	return ((Loops*Thread_Number) / Comp_Time)/1000;
    }
    else
    { 
    #if IsLin
	Little_Mutex_Helper Mutex;
	
	watch.Start();
	Intern_MultiT_MLuL_Test< Loops > ( &Mutex.m_Mutex );
    #elif IsWin
	CRITICAL_SECTION CS; //Is critical section relly the right choice?
	InitializeCriticalSection( &CS );
    
	watch.Start();
	Intern_MultiT_MLuL_Test< Loops > ( &CS );
    #endif
    
	watch.Stop( &Comp_Time );	
	
	return (Loops / Comp_Time)/1000;
    }
}
예제 #28
0
//todo: Use a typedef for the saving type
void Benchmark::Run()
{
		Stopwatch watch;
		uint32_t tmp_Time;
		if( ::Just_Mem_Test )
		    tmp_Time = Time_Per_Test * 5;
		else if( ::Just_Cpu_Test )
		    tmp_Time = Time_Per_Test * 7;
		else if( ::Just_MT_Test )
		    tmp_Time = Time_Per_Test * 1;
		else
		    tmp_Time = Time_Per_Test * 13;
		    
		if( No_Cpu_Test )
		    tmp_Time -= Time_Per_Test * 7;
		if( No_Mem_Test )
		    tmp_Time -= Time_Per_Test * 5;
		if( No_MT_Test )
		    tmp_Time -= Time_Per_Test * 1;
		
		
		const uint32_t Time( tmp_Time );
		uint32_t Loops(0);
		
		double   Re8int(0),
		         Re16int(0),
		         Re32int(0),
		         Re64int(0),
		         Re32Fp(0),
		         Re64Fp(0),
		         Re96Fp(0),
		         Re128Fp(0),
		         ReMemRW2(0),
		         ReMemRW4(0),
		         ReMemDA2(0),
		         ReMemDA4(0),
		         ReMemDA8(0),
		         ReMTMLuL(0);
		         
		double Cur_Time(0);
		Status_Done(0);
		watch.Start();
		for( ; Cur_Time < Time; ++Loops, watch.Look( Cur_Time ), Status_Done( static_cast< uint32_t >( (100.0/Time)*Cur_Time  )) )
		{
			if( !Just_Mem_Test && !Just_MT_Test  &&  !No_Cpu_Test)
			{
			    Re8int += static_cast< double > (Intern_Integer8_Test() );
			    if( m_Error )
			    	return;
			    Re16int += static_cast< double > (Intern_Integer16_Test() );
			    if( m_Error )
			    	return;
			    Re32int += static_cast< double > (Intern_Integer32_Test() );
			    if( m_Error )
			    	return;
			    Re64int += static_cast< double > (Intern_Integer64_Test() );
			
			    Re32Fp += static_cast< double > (Intern_Fp32_Test() );
			    if( m_Error )
			    	return;
			    Re64Fp += static_cast< double > (Intern_Fp64_Test() );
			    if( m_Error )
			    	return;
			    if( sizeof( long double ) == 12 )
			        Re96Fp += static_cast< double > (Intern_Fp96_Test() );
			    else if( sizeof( long double ) == 16 )
			        Re128Fp += static_cast< double > (Intern_Fp128_Test() );

			    if( m_Error )
			    	return;
			}
			if( !Just_Cpu_Test &&  !Just_MT_Test && !No_Mem_Test)
			{
			    ReMemRW2 += static_cast< double > (Intern_Mem_RW2_Test() );
			    if( m_Error )
				return;
			    ReMemRW4 += static_cast< double > (Intern_Mem_RW4_Test() );
			    if( m_Error )
			    	return;
			    ReMemDA2 += static_cast< double > (Intern_Mem_DA2_Test() );
			    if( m_Error )
			    	return;
			    ReMemDA8 += static_cast< double > (Intern_Mem_DA8_Test() );
			    if( m_Error )
			    	return;
			    ReMemDA4 += static_cast< double > (Intern_Mem_DA4_Test() ); 
			    if( m_Error )
			    	return;
			}
			if( !Just_Cpu_Test && !Just_Mem_Test  && !No_MT_Test )
			{
			    ReMTMLuL += static_cast< double > (Intern_MT_MLuL_Test() );
			    if( m_Error )
			        return;
			}
		}
		
		if( !Just_Mem_Test && !Just_MT_Test  && !No_Cpu_Test)
		{
		    //Todo:Change the cast to use the typedef!
		    m_Integer8_Score = static_cast< Benchmark::Score_Type >  ( (Re8int / static_cast<double> (Loops) )  );
		    m_Integer16_Score = static_cast< Benchmark::Score_Type > ( (Re16int / static_cast<double> (Loops) ) );
		    m_Integer32_Score = static_cast< Benchmark::Score_Type > ( (Re32int / Loops ) );
		    m_Integer64_Score = static_cast< Benchmark::Score_Type > ( (Re64int / static_cast<double> (Loops) ) );
		
		
		    m_Fp32_Score = static_cast< Benchmark::Score_Type >  ( (Re32Fp / static_cast<double> (Loops) ) );
		    m_Fp64_Score = static_cast< Benchmark::Score_Type >  ( (Re64Fp / static_cast<double> (Loops) ) );
		    m_Fp96_Score = static_cast< Benchmark::Score_Type >  ( (Re96Fp / static_cast<double> (Loops) ) );
		    m_Fp128_Score = static_cast< Benchmark::Score_Type > ( (Re128Fp / static_cast<double>(Loops) ) );
		}
		if( !Just_Cpu_Test  &&  !Just_MT_Test  && !No_Mem_Test)
		{
		    m_Mem_RW2_Score = static_cast< Benchmark::Score_Type > ( ReMemRW2 / Loops );
		    m_Mem_RW4_Score = static_cast< Benchmark::Score_Type > ( ReMemRW4 / Loops );
		    m_Mem_DA2_Score = static_cast< Benchmark::Score_Type > ( ReMemDA2 / Loops );
		    m_Mem_DA4_Score = static_cast< Benchmark::Score_Type > ( ReMemDA4 / Loops );
		    m_Mem_DA8_Score = static_cast< Benchmark::Score_Type > ( ReMemDA8 / Loops );
		}
		if( !Just_Cpu_Test && ! Just_Mem_Test && !No_MT_Test)
		{
			m_MT_MLuL_Score = static_cast< Benchmark::Score_Type > ( ReMTMLuL / Loops );
		}
	
	
}
예제 #29
0
        Awaitable<void> ReplicatorPerfTest::Run(
            __in wstring const & testFolder,
            __in int concurrentTransactions,
            __in int totalTransactions,
            __in Data::Log::LogManager & logManager)
        {
#ifndef PERF_TEST
            UNREFERENCED_PARAMETER(testFolder);
            UNREFERENCED_PARAMETER(concurrentTransactions);
            UNREFERENCED_PARAMETER(totalTransactions);
            UNREFERENCED_PARAMETER(logManager);
#else
            Replica::SPtr replica = Replica::Create(
                pId_,
                rId_,
                testFolder,
                logManager,
                underlyingSystem_->PagedAllocator());

            co_await replica->OpenAsync();

            FABRIC_EPOCH epoch1; epoch1.DataLossNumber = 1; epoch1.ConfigurationNumber = 1; epoch1.Reserved = nullptr;
            co_await replica->ChangeRoleAsync(epoch1, FABRIC_REPLICA_ROLE_PRIMARY);

            replica->SetReadStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_GRANTED);
            replica->SetWriteStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_GRANTED);

            KUri::CSPtr stateProviderName = GetStateProviderName(0);
            {
                Transaction::SPtr txn;
                replica->TxnReplicator->CreateTransaction(txn);
                KFinally([&] {txn->Dispose(); });

                NTSTATUS status = co_await replica->TxnReplicator->AddAsync(*txn, *stateProviderName, L"ReplicatorPerfTest");
                VERIFY_IS_TRUE(NT_SUCCESS(status));
                co_await txn->CommitAsync();
            }

            {
                IStateProvider2::SPtr stateProvider2;
                NTSTATUS status = replica->TxnReplicator->Get(*stateProviderName, stateProvider2);
                VERIFY_IS_TRUE(NT_SUCCESS(status));
                VERIFY_IS_NOT_NULL(stateProvider2);
                VERIFY_ARE_EQUAL(*stateProviderName, stateProvider2->GetName());

                IStore<int, int>::SPtr store = dynamic_cast<IStore<int, int>*>(stateProvider2.RawPtr());

                Stopwatch s;
                s.Start();

                KArray<Awaitable<void>> tasks(underlyingSystem_->PagedAllocator(), concurrentTransactions, 0);

                for (int i = 0; i < concurrentTransactions; i++)
                {
                    status = tasks.Append(DoWorkOnKey(store, replica, totalTransactions / concurrentTransactions, i));
                    KInvariant(NT_SUCCESS(status));
                }

                co_await TaskUtilities<Awaitable<void>>::WhenAll(tasks);

                s.Stop();

                int64 txPerSec = ((totalTransactions * 1000) / s.ElapsedMilliseconds);

                Trace.WriteInfo(
                    TraceComponent,
                    "{0}: Tx/Sec is {1}",
                    prId_->TraceId,
                    txPerSec);
            }

            replica->SetReadStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_NOT_PRIMARY);
            replica->SetWriteStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_NOT_PRIMARY);

            co_await replica->CloseAsync();
#endif
            co_return;
        }
예제 #30
0
파일: viewer.cpp 프로젝트: Len3d/OpenSubdiv
//------------------------------------------------------------------------------
static void
display() {

    // set effect
    g_effect.displayStyle = g_displayStyle;
    g_effect.screenSpaceTess = (g_screenSpaceTess != 0);
    g_effect.displayPatchColor = (g_displayPatchColor != 0);

    // prepare view matrix
    float aspect = g_width/(float)g_height;
    float modelview[16], projection[16];
    identity(modelview);
    translate(modelview, -g_pan[0], -g_pan[1], -g_dolly);
    rotate(modelview, g_rotate[1], 1, 0, 0);
    rotate(modelview, g_rotate[0], 0, 1, 0);
    rotate(modelview, -90, 1, 0, 0);
    translate(modelview, -g_center[0], -g_center[1], -g_center[2]);
    perspective(projection, 45.0f, aspect, 0.01f, 500.0f);

    g_effect.SetMatrix(modelview, projection);
    g_effect.SetTessLevel((float)(1 << g_tessLevel));
    g_effect.SetLighting();

    // -----------------------------------------------------------------------
    // prepare draw items

    Stopwatch s;
    s.Start();

    OpenSubdiv::OsdUtilDrawItem<MyDrawDelegate::EffectHandle, MyDrawContext>::Collection items;
    OpenSubdiv::OsdUtilDrawItem<MyDrawDelegate::EffectHandle, MyDrawContext>::Collection cachedDrawItems;

    int numModels = g_modelCount*g_modelCount;
    items.reserve(numModels);

    for (int i = 0; i < numModels; ++i) {
        // Here, client can pack arbitrary mesh and effect into drawItems.

        items.push_back(OpenSubdiv::OsdUtilDrawItem<MyDrawDelegate::EffectHandle, MyDrawContext>(
                            g_batch, &g_effect, g_batch->GetPatchArrays(i)));
    }

    if (g_batching) {
        // create cached draw items
        OpenSubdiv::OsdUtil::OptimizeDrawItem(items, cachedDrawItems, &g_drawDelegate);
    }

    s.Stop();
    float prepCpuTime = float(s.GetElapsed() * 1000.0f);

    // -----------------------------------------------------------------------
    // draw items
    s.Start();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0, 0, g_width, g_height);

    // primitive counting
    glBeginQuery(GL_PRIMITIVES_GENERATED, g_queries[0]);
#if defined(GL_VERSION_3_3)
    glBeginQuery(GL_TIME_ELAPSED, g_queries[1]);
#endif
    g_drawDelegate.ResetNumDrawCalls();

    if (g_displayStyle == kWire) glDisable(GL_CULL_FACE);

    if (g_batching) {
        OpenSubdiv::OsdUtil::DrawCollection(cachedDrawItems, &g_drawDelegate);
    } else {
        OpenSubdiv::OsdUtil::DrawCollection(items, &g_drawDelegate);
    }

    if (g_displayStyle == kWire) glEnable(GL_CULL_FACE);

    glEndQuery(GL_PRIMITIVES_GENERATED);
#if defined(GL_VERSION_3_3)
    glEndQuery(GL_TIME_ELAPSED);
#endif

    s.Stop();
    float drawCpuTime = float(s.GetElapsed() * 1000.0f);

    // -----------------------------------------------------------------------

    GLuint numPrimsGenerated = 0;
    GLuint timeElapsed = 0;
    glGetQueryObjectuiv(g_queries[0], GL_QUERY_RESULT, &numPrimsGenerated);
#if defined(GL_VERSION_3_3)
    glGetQueryObjectuiv(g_queries[1], GL_QUERY_RESULT, &timeElapsed);
#endif
    float drawGpuTime = timeElapsed / 1000.0f / 1000.0f;

    if (g_hud.IsVisible()) {
        g_fpsTimer.Stop();
        g_totalTime += g_fpsTimer.GetElapsed();
        double fps = 1.0/g_fpsTimer.GetElapsed();
        g_fpsTimer.Start();
        g_hud.DrawString(10, -200, "Draw Calls : %d", g_drawDelegate.GetNumDrawCalls());
        g_hud.DrawString(10, -180, "Tess level : %d", g_tessLevel);
        g_hud.DrawString(10, -160, "Primitives : %d", numPrimsGenerated);
        g_hud.DrawString(10, -120, "GPU Kernel : %.3f ms", g_gpuTime);
        g_hud.DrawString(10, -100, "CPU Kernel : %.3f ms", g_cpuTime);
        g_hud.DrawString(10, -80,  "GPU Draw   : %.3f ms", drawGpuTime);
        g_hud.DrawString(10, -60,  "CPU Draw   : %.3f ms", drawCpuTime);
        g_hud.DrawString(10, -40,  "CPU Prep   : %.3f ms", prepCpuTime);
        g_hud.DrawString(10, -20,  "FPS        : %3.1f", fps);

        g_hud.Flush();
    }

    checkGLErrors("display leave");
    glFinish();
}