timing

Input with a timeout in C++

寵の児 提交于 2020-01-10 03:05:30
问题 I want to have a program where the user have 10 seconds to enter the password. If the timer goes over 10 seconds, the program displays a message. My current code is this: #include <iostream> #include <ctime> #include <string> int main(){ std::string password; int start_s=clock(); int stop_s=clock(); if(stop_s-start_s <= 0){ std::cout << "TIME RAN OUT!"; } std::cout << "Enter your password! \n"; std::cout << "Password: "; std::cin >> password; std::cout << "\n \n"; if (password == "password123

timing of multiple function calls

安稳与你 提交于 2020-01-06 03:53:09
问题 Coming from python I am trying to find a way to time several function calls in a c++ code. So far I am using this. void my_func(/*some args*/) { clock_t t_begin = std::clock(); // code clock_t t_end = std::clock(); double elapsed_secs_U = double(t_end - t_begin) / CLOCKS_PER_SEC; } But this is highly repetitive. And I would like to have something like a function wrapper so that I can write: void timer(func, *args) { clock_t t_begin = std::clock(); func(*args) clock_t t_end = std::clock();

Timed events with php/MySQL

﹥>﹥吖頭↗ 提交于 2020-01-03 17:55:14
问题 I need a way to modify a value in a table after a certain amount of time has passed. My current method is as follow: insert end time for wait period in table when a user loads a page requesting the value to be changed, check to see if current >= end time if it is, change the value and remove the end time field, if it isn't, do nothing This is going to be a major feature on the site, and so efficiency is the key; with that in mind, you can probably see the problem with how I'm doing it. That

Timed events with php/MySQL

谁说我不能喝 提交于 2020-01-03 17:54:59
问题 I need a way to modify a value in a table after a certain amount of time has passed. My current method is as follow: insert end time for wait period in table when a user loads a page requesting the value to be changed, check to see if current >= end time if it is, change the value and remove the end time field, if it isn't, do nothing This is going to be a major feature on the site, and so efficiency is the key; with that in mind, you can probably see the problem with how I'm doing it. That

OpenGL, measuring rendering time on gpu

旧巷老猫 提交于 2020-01-03 16:51:50
问题 I have some big performance issues here So I would like to take some measurements on the gpu side. By reading this thread I wrote this code around my draw functions, including the gl error check and the swapBuffers() (auto swapping is indeed disabled) gl4.glBeginQuery(GL4.GL_TIME_ELAPSED, queryId[0]); { draw(gl4); checkGlError(gl4); glad.swapBuffers(); } gl4.glEndQuery(GL4.GL_TIME_ELAPSED); gl4.glGetQueryObjectiv(queryId[0], GL4.GL_QUERY_RESULT, frameGpuTime, 0); And since OpenGL rendering

OpenGL, measuring rendering time on gpu

拈花ヽ惹草 提交于 2020-01-03 16:51:18
问题 I have some big performance issues here So I would like to take some measurements on the gpu side. By reading this thread I wrote this code around my draw functions, including the gl error check and the swapBuffers() (auto swapping is indeed disabled) gl4.glBeginQuery(GL4.GL_TIME_ELAPSED, queryId[0]); { draw(gl4); checkGlError(gl4); glad.swapBuffers(); } gl4.glEndQuery(GL4.GL_TIME_ELAPSED); gl4.glGetQueryObjectiv(queryId[0], GL4.GL_QUERY_RESULT, frameGpuTime, 0); And since OpenGL rendering

My code takes a screenshot of a program when it becomes the foreground window. Running into a small issue with the timing of the screenshots

谁说我不能喝 提交于 2020-01-03 05:13:11
问题 I have this line of code in my main method: IntPtr hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT); Then I have this in my class: delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime); static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint

Accurate timing for imports in Python

我是研究僧i 提交于 2020-01-02 07:48:06
问题 The timeit module is great for measuring the execution time of small code snippets but when the code changes global state (like timeit ) it's really hard to get accurate timings. For example if I want to time it takes to import a module then the first import will take much longer than subsequent imports, because the submodules and dependencies are already imported and the files are already cached. So using a bigger number of repeats, like in: >>> import timeit >>> timeit.timeit('import numpy'

High precision timing in userspace in Linux

怎甘沉沦 提交于 2020-01-01 06:35:20
问题 Right now, I'm trying to determine a method to measure the time that a particular function will take (something like pthread_create). Now, of course, these types of functions are extremely optimized to take as little time as possible; so little, in fact, that my timer that uses gettimeofday in userspace which measures in microseconds is unable to adequately measure anything. Normally, if I could mess with the kernel, I'd use something like get_cycles to measure the raw number of cycles as a

Precisely measure execution time of code in thread (C#)

断了今生、忘了曾经 提交于 2020-01-01 04:22:07
问题 I'm trying to measure the execution time of some bits of code as accurately as possible on a number of threads, taking context switching and thread downtime into account. The application is implemented in C# (VS 2008). Example: public void ThreadFunc () { // Some code here // Critical block #1 begins here long lTimestamp1 = Stopwatch.GetTimestamp (); CallComplex3rdPartyFunc (); // A long lTimestamp2 = Stopwatch.GetTimestamp (); // Critical block #1 ends here // Some code here // Critical