//------------------------------------------------------------------------------ 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"); }
//------------------------------------------------------------------------------ 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); }
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); }
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); } }
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); }
/** * @fn Keyboard(unsigned char key, int x, int y) * @brief GLUT keyboard callback. */ void Keyboard(unsigned char key, int x, int y) { switch(key) { case 'q': case 'Q': case 27: Shutdown(); exit(0); break; case '.': g_bSingleStep = true; break; case 'p': g_bPause = !g_bPause; break; case 'a': g_bArbitraryBC = !g_bArbitraryBC; g_pFlo->EnableArbitraryBC(g_bArbitraryBC); break; case 'c': g_bClearPressure = !g_bClearPressure; g_pFlo->EnablePressureClear(g_bClearPressure); break; case 'r': g_pFlo->Reset(); break; case 'R': g_pFlo->Reset(true); break; case 'v': g_bComputeVorticity = !g_bComputeVorticity; g_pFlo->EnableVCForce(g_bComputeVorticity); break; case '~': case '`': g_bDisplaySliders = !g_bDisplaySliders; break; case 't': g_displayMode = static_cast<Flo::DisplayMode>(((g_displayMode + 1) % Flo::DISPLAY_COUNT)); break; case 'T': g_bDisplayFluid = !g_bDisplayFluid; break; case 'b': g_bBilerp = !g_bBilerp; break; case 'm': g_bMakeTex = !g_bMakeTex; break; case 'L': g_perfTimer.Stop(); g_perfTimer.Reset(); g_bTiming = true; break; default: break; } }
void Application::Run() { Stopwatch watch; // 理想状况 60 帧每秒 const DWORD desiredDelta = 1000 / 30; // 上一次每帧用时 DWORD lastDelta = desiredDelta; while (true) { try { watch.Restart(); if (DoFrame()) break; // 本帧用时 lastDelta = static_cast<DWORD>(watch.Stop() * 1000); // Sleep 剩余时间 if (lastDelta < desiredDelta) Sleep(desiredDelta - lastDelta); } catch (...) { bool handled = false; OnUncaughtException(handled); // 异常未处理 if (!handled) throw; } } }
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; }
__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"; } }
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; }
//------------------------------------------------------------------------------------------------- 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); }
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(); } }
void MyPerformanceReporter::ReportTestFinish(UnitTest::TestDetails const& test, float secondsElapsed) { Counter.Stop(); if (lastsuitename != test.suiteName) { outputFile << endl << endl << test.suiteName <<endl; lastsuitename = test.suiteName; } outputFile << test.testName << ";" << (secondsElapsed*1000) << "ms" << endl; }
double OsdMesh::Synchronize() { Stopwatch s; s.Start(); { _dispatcher->Synchronize(); } s.Stop(); return s.GetElapsed(); }
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"; }
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(); }
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); }
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! } }
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; } }
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; } }
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; } }
//------------------------------------------------------------------------------ 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(); }
static void updateGeom(bool forceAll) { float r = (float)sin(g_totalTime); for (int j = 0; j < g_modelCount * g_modelCount; ++j) { if (forceAll == false && j >= g_moveModels) break; int nverts = (int)g_positions[j].size()/3; std::vector<float> vertex, varying; vertex.reserve(nverts * 3); if (g_displayStyle == kVaryingColor) varying.reserve(nverts * 3); const float *p = &g_positions[j][0]; for (int i = 0; i < nverts; ++i) { float ct = cos(p[2] * r); float st = sin(p[2] * r); float v[4]; v[0] = p[0]*ct + p[1]*st; v[1] = -p[0]*st + p[1]*ct; v[2] = p[2]; v[3] = 1; apply(v, g_transforms[j].value); vertex.push_back(v[0]); vertex.push_back(v[1]); vertex.push_back(v[2]); if (g_displayStyle == kVaryingColor) { varying.push_back(p[2]); varying.push_back(p[1]); varying.push_back(p[0]); } p += 3; } g_batch->UpdateCoarseVertices(j, &vertex[0], nverts); if (g_displayStyle == kVaryingColor) { g_batch->UpdateCoarseVaryings(j, &varying[0], nverts); } } Stopwatch s; s.Start(); g_batch->FinalizeUpdate(); s.Stop(); g_cpuTime = float(s.GetElapsed() * 1000.0f); s.Start(); if (g_kernel == kCPU) Controller<OpenSubdiv::OsdCpuComputeController>::GetInstance()->Synchronize(); #ifdef OPENSUBDIV_HAS_OPENMP else if (g_kernel == kOPENMP) Controller<OpenSubdiv::OsdOmpComputeController>::GetInstance()->Synchronize(); #endif #ifdef OPENSUBDIV_HAS_OPENCL else if (g_kernel == kCL) Controller<OpenSubdiv::OsdCLComputeController>::GetInstance()->Synchronize(); #endif #ifdef OPENSUBDIV_HAS_CUDA else if (g_kernel == kCUDA) Controller<OpenSubdiv::OsdCudaComputeController>::GetInstance()->Synchronize(); #endif #ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK else if (g_kernel == kGLSL) Controller<OpenSubdiv::OsdGLSLTransformFeedbackComputeController>::GetInstance()->Synchronize(); #endif s.Stop(); g_gpuTime = float(s.GetElapsed() * 1000.0f); }
void TestTree(T _tree, DArray<ktype_t> *dataset, unsigned long _size) { console->Write("%10lu ", _size); // fill tree Stopwatch sw; sw.Start(); for (size_t i = 0; i < _size; i++) { ktype_t item = dataset->get(i); _tree->insert(item, item); } sw.Stop(); console->Write("%9.5lfs ", sw.Elapsed()); DArray<ktype_t> searchItems; // create valid item list searchItems.empty(); while (searchItems.used() < MaxSearches) { unsigned long idx = RandomNumber() % _size; searchItems.insert(dataset->get(idx)); } // successful searches sw.Start(); for (size_t i = 0; i < MaxSearches; i++) { _tree->find(searchItems[i], 0); } sw.Stop(); console->Write("%9.5lfs ", sw.Elapsed()); // create mixed item list searchItems.empty(); while (searchItems.used() < MaxSearches) { unsigned long idx; idx = RandomNumber() % _size; searchItems.insert(dataset->get(idx)); idx = _size + (RandomNumber() % _size); searchItems.insert(dataset->get(idx)); } // mixed success searches sw.Start(); for (size_t i = 0; i < MaxSearches; i++) { _tree->find(searchItems[i], 0); } sw.Stop(); console->Write("%9.5lfs ", sw.Elapsed()); // create invalid item list searchItems.empty(); while (searchItems.used() < MaxSearches) { unsigned long idx = _size + (RandomNumber() % _size); searchItems.insert(dataset->get(idx)); } // invalid searches sw.Start(); for (size_t i = 0; i < MaxSearches; i++) { _tree->find(searchItems[i], 0); } sw.Stop(); console->Write("%9.5lfs ", sw.Elapsed()); // empty tree sw.Start(); _tree->empty(); sw.Stop(); console->WriteLine("%9.5lfs", sw.Elapsed()); }
__attribute__((noinline)) void benchmarkROOTNavigator(SOA3D<Precision> const &points, SOA3D<Precision> const &dirs) { TGeoNavigator *rootnav = ::gGeoManager->GetCurrentNavigator(); auto nPoints = points.size(); TGeoBranchArray **instates = new TGeoBranchArray *[nPoints]; TGeoBranchArray **outstates = new TGeoBranchArray *[nPoints]; Precision *steps = new Precision[points.size()]; Precision *safeties; if (WithSafety) { safeties = new Precision[points.size()]; } // we don't have the input state container in ROOT form // we generate them but do not take this into account for the timing measurement for (size_t i = 0; i < nPoints; ++i) { Vector3D<Precision> const &pos = points[i]; rootnav->ResetState(); rootnav->FindNode(pos.x(), pos.y(), pos.z()); instates[i] = TGeoBranchArray::MakeInstance(GeoManager::Instance().getMaxDepth()); outstates[i] = TGeoBranchArray::MakeInstance(GeoManager::Instance().getMaxDepth()); instates[i]->InitFromNavigator(rootnav); } #ifdef CALLGRIND_ENABLED CALLGRIND_START_INSTRUMENTATION; #endif Stopwatch timer; timer.Start(); for (size_t i = 0; i < nPoints; ++i) { Vector3D<Precision> const &pos = points[i]; Vector3D<Precision> const &dir = dirs[i]; rootnav->ResetState(); instates[i]->UpdateNavigator(rootnav); rootnav->SetCurrentPoint(pos.x(), pos.y(), pos.z()); rootnav->SetCurrentDirection(dir.x(), dir.y(), dir.z()); if (WithSafety) { safeties[i] = rootnav->Safety(true); } if (WithReloc) { volatile TGeoNode *node = rootnav->FindNextBoundaryAndStep(kInfLength); (void)node; } else { volatile TGeoNode *node = rootnav->FindNextBoundary(kInfLength); (void)node; } steps[i] = rootnav->GetStep(); if (WithReloc) { // save output states ( for fair comparison with VecGeom ) outstates[i]->InitFromNavigator(rootnav); } } timer.Stop(); #ifdef CALLGRIND_ENABLED CALLGRIND_STOP_INSTRUMENTATION; CALLGRIND_DUMP_STATS; #endif std::cerr << timer.Elapsed() << "\n"; double accum(0.); double saccum(0.); size_t hittargetchecksum = 0L; for (decltype(points.size()) i = 0; i < points.size(); ++i) { accum += steps[i]; if (WithSafety) { saccum += safeties[i]; } // target checksum via the table held from RootGeoManager hittargetchecksum += (size_t)RootGeoManager::Instance().Lookup(outstates[i]->GetNode(outstates[i]->GetLevel()))->id(); } delete[] steps; if (WithSafety) { delete safeties; } // cleanup states for (decltype(points.size()) i = 0; i < points.size(); ++i) { delete instates[i]; delete outstates[i]; } delete[] instates; delete[] outstates; std::cerr << "accum TGeo " << accum << " target checksum " << hittargetchecksum << "\n"; if (WithSafety) { std::cerr << "safety accum TGeo " << saccum << "\n"; } }
void MessageConnection::OnRead() { bool yield, closed; unsigned pos, msglength, nread, msgbegin, msgend, required; uint64_t start; Stopwatch sw; ReadBuffer msg; if (!readActive) { if (resumeRead.IsActive()) STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false."); EventLoop::Add(&resumeRead); return; } sw.Start(); Log_Trace("Read buffer: %B", tcpread.buffer); tcpread.requested = IO_READ_ANY; pos = 0; start = NowClock(); yield = false; while(true) { msglength = BufferToUInt64(tcpread.buffer->GetBuffer() + pos, tcpread.buffer->GetLength() - pos, &nread); if (msglength > tcpread.buffer->GetSize() - NumDigits(msglength) - 1) { Log_Trace(); required = msglength + NumDigits(msglength) + 1; if (required > MESSAGING_MAX_SIZE) { Log_Trace(); OnClose(); return; } tcpread.buffer->Allocate(required); break; } if (nread == 0 || (unsigned) tcpread.buffer->GetLength() - pos <= nread) break; if (tcpread.buffer->GetCharAt(pos + nread) != ':') { Log_Trace("Message protocol error"); OnClose(); return; } msgbegin = pos + nread + 1; msgend = pos + nread + 1 + msglength; if ((unsigned) tcpread.buffer->GetLength() < msgend) { // read more //tcpread.requested = msgend - pos; break; } msg.SetBuffer(tcpread.buffer->GetBuffer() + msgbegin); msg.SetLength(msglength); closed = OnMessage(msg); if (closed) return; pos = msgend; // if the user called Close() in OnMessageRead() if (state != CONNECTED) return; if (tcpread.buffer->GetLength() == msgend) break; if (NowClock() - start >= YIELD_TIME || !readActive) { // let other code run every YIELD_TIME msec yield = true; if (resumeRead.IsActive()) STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false."); EventLoop::Add(&resumeRead); break; } } if (pos > 0) { memmove(tcpread.buffer->GetBuffer(), tcpread.buffer->GetBuffer() + pos, tcpread.buffer->GetLength() - pos); tcpread.buffer->Shorten(pos); } if (state == CONNECTED && !tcpread.active && !yield) IOProcessor::Add(&tcpread); sw.Stop(); Log_Trace("time spent in OnRead(): %U", sw.Elapsed()); }
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; }
__attribute__((noinline)) void benchmarkG4Navigator(SOA3D<Precision> const &points, SOA3D<Precision> const &dirs) { G4VPhysicalVolume *world(vecgeom::G4GeoManager::Instance().GetG4GeometryFromROOT()); if (world != nullptr) G4GeoManager::Instance().LoadG4Geometry(world); // Note: Vector3D's are expressed in cm, while G4ThreeVectors are expressed in mm const Precision cm = 10.; // cm --> mm conversion G4Navigator &g4nav = *(G4GeoManager::Instance().GetNavigator()); // G4TouchableHistory **g4history = new G4TouchableHistory *[nPoints]; Precision *steps = new Precision[points.size()]; // get a time estimate to just to locate points // (The reason is that the G4Navigator has a huge internal state and it is not foreseen to do // multi-track processing with a basked of G4TouchableHistories as states) Stopwatch timer; timer.Start(); for (decltype(points.size()) i = 0; i < points.size(); ++i) { G4ThreeVector g4pos(points[i].x() * cm, points[i].y() * cm, points[i].z() * cm); G4ThreeVector g4dir(dirs[i].x(), dirs[i].y(), dirs[i].z()); // false --> locate from top g4nav.LocateGlobalPointAndSetup(g4pos, &g4dir, false); } Precision timeForLocate = (Precision)timer.Stop(); #ifdef CALLGRIND_ENABLED CALLGRIND_START_INSTRUMENTATION; #endif timer.Start(); for (decltype(points.size()) i = 0; i < points.size(); ++i) { G4ThreeVector g4pos(points[i].x() * cm, points[i].y() * cm, points[i].z() * cm); G4ThreeVector g4dir(dirs[i].x(), dirs[i].y(), dirs[i].z()); G4double maxStep = kInfLength; // false --> locate from top G4VPhysicalVolume const *vol = g4nav.LocateGlobalPointAndSetup(g4pos, &g4dir, false); (void)vol; G4double safety = 0.0; steps[i] = g4nav.ComputeStep(g4pos, g4dir, maxStep, safety); G4ThreeVector nextPos = g4pos + (steps[i] + 1.0e-6) * g4dir; // TODO: save touchable history array - returnable? symmetrize with ROOT/VECGEOM benchmark g4nav.SetGeometricallyLimitedStep(); volatile G4VPhysicalVolume const *nextvol = g4nav.LocateGlobalPointAndSetup(nextPos); (void)nextvol; } timer.Stop(); std::cerr << (Precision)timer.Elapsed() - timeForLocate << "\n"; #ifdef CALLGRIND_ENABLED CALLGRIND_STOP_INSTRUMENTATION; CALLGRIND_DUMP_STATS; #endif // cleanup // delete[] g4history; //_mm_free(maxSteps); double accum{0.}; size_t hittargetchecksum{0L}; for (decltype(points.size()) i = 0; i < points.size(); ++i) { accum += steps[i]; if (WithSafety) { // saccum += safeties[i]; } // target checksum via the table held from RootGeoManager // hittargetchecksum += // (size_t)RootGeoManager::Instance().Lookup(outstates[i]->GetNode(outstates[i]->GetLevel()))->id(); } std::cerr << "accum G4 " << accum / cm << " target checksum " << hittargetchecksum << "\n"; }