void main(void) { int len, i, j, off, sec; char *addr = (char *)SDRAM_BASE + (1 << 20); /* download at + 1MB */ char *addr2 = (char *)SDRAM_BASE + (2 << 20); /* readback to + 2MB */ SPI_InitFlash(); printf("Waiting for data\n"); while ((len = xmodem_rx(addr)) == -1) continue; printf("Writing %u bytes at %u\n", len, OFFSET); for (i = 0; i < len; i+= FLASH_PAGE_SIZE) { off = i + OFFSET; for (j = 0; j < 10; j++) { SPI_WriteFlash(off, addr + i, FLASH_PAGE_SIZE); SPI_ReadFlash(off, addr2 + i, FLASH_PAGE_SIZE); if (p_memcmp(addr + i, addr2 + i, FLASH_PAGE_SIZE) == 0) break; } if (j >= 10) printf("Bad Readback at %u\n", i); } sec = GetSeconds() + 2; while (sec <= GetSeconds()) continue; printf("Done\n"); reset(); }
int main() { srand (time(0)); int temp; for (int i =0;i<SIZE;i++){ temp=rand() % 10000 + 1; data[i]=temp; data2[i]=temp; } ResetMilli(); bitonic_cpu(data, SIZE); printf("CPU:%f\n", GetSeconds()); ResetMilli(); #ifdef GPU bitonic_gpu(data2, SIZE); printf("GPU:%f\n", GetSeconds()); for (int i=0;i<SIZE;i++) if (data[i] != data2[i]) { printf("Error at %d ", i); return(1); } #endif // Print result if (SIZE <= MAXPRINTSIZE) for (int i=0;i<SIZE;i++) printf("%d ", data[i]); printf("\nYour sorting looks correct!\n"); }
//////////////////////////////////////////////////////////////////////////////// // main computation function //////////////////////////////////////////////////////////////////////////////// void computeImages() { //read in full size of memory image = readppm("maskros512.ppm", &n, &m); out = (unsigned char*) malloc(n*m*3); cl_mem in_data, out_data; cl_int ciErrNum = CL_SUCCESS; // Create space for data and copy image to device (note that we could also use clEnqueueWriteBuffer to upload) in_data = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, 3*n*m * sizeof(unsigned char), image, &ciErrNum); printCLError(ciErrNum,6); out_data = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, 3*n*m * sizeof(unsigned char), NULL, &ciErrNum); printCLError(ciErrNum,7); // set the args values ciErrNum = clSetKernelArg(theKernel, 0, sizeof(cl_mem), (void *) &in_data); ciErrNum |= clSetKernelArg(theKernel, 1, sizeof(cl_mem), (void *) &out_data); ciErrNum |= clSetKernelArg(theKernel, 2, sizeof(cl_uint), (void *) &n); ciErrNum |= clSetKernelArg(theKernel, 3, sizeof(cl_uint), (void *) &m); printCLError(ciErrNum,8); // Computing arrangement //size_t localWorkSize, globalWorkSize; size_t globalWorkSize[3] = {512, 512, 1}; size_t localWorkSize[3] = {16, 16, 1}; //256 threads in each block // 32*32 (1024) blocks in total to have 512*512 threads in total printf("Startup time %lf\n", GetSeconds()); // Compute! cl_event event; ResetMilli(); ciErrNum = clEnqueueNDRangeKernel(commandQueue, theKernel, 2, NULL, &globalWorkSize, &localWorkSize, 0, NULL, &event); printCLError(ciErrNum,9); ciErrNum = clWaitForEvents(1, &event); // Synch printCLError(ciErrNum,10); printf("time %lf\n", GetSeconds()); ciErrNum = clEnqueueReadBuffer(commandQueue, out_data, CL_TRUE, 0, 3*n*m * sizeof(unsigned char), out, 0, NULL, &event); printCLError(ciErrNum,11); clWaitForEvents(1, &event); // Synch printCLError(ciErrNum,10); clReleaseMemObject(in_data); clReleaseMemObject(out_data); return; }
// 注册线程 void CDlgAutoRegister::Run() { ResetEvent(m_hEventTheadNoRun1); ::CoInitialize(NULL); int nStart = GetSeconds(m_config.m_startTime); int nLast = GetSeconds(m_config.m_endTime); while(1) { int nCurrent = (int)time(NULL); // if (nCurrent > nLast) // { // PostMessage(M_TASK_OVER); // SetEvent(m_hEventTheadNoRun1); // ::CoUninitialize(); // return; // } try { if (nCurrent >= nStart) { int n = m_arrayTasks.size(); for (int i = 0; i < (int)m_arrayTasks.size(); i++) { TaskNode& task = m_arrayTasks[i]; //Sleep(task.nDeltaSeconds S); SleepThread(task.nDeltaSeconds, 1); RegisterID(task); } ::CoUninitialize(); PostMessage(M_TASK_OVER); SetEvent(m_hEventTheadNoRun1); return ; } } catch(...) { IBA_LOG0(_T("出现异常1")); } //Sleep(1 S); SleepThread(1,1); } ::CoUninitialize(); PostMessage(M_TASK_OVER); SetEvent(m_hEventTheadNoRun1); }
// 计算出Lua调用一个函数需要的大约时间 static double calcCallTime(lua_State *L) { sqr::uint64 timer; char Code[] = " \ function MesureFunc() \ local i \ \ local t = function() \ end \ \ i = 1 \ while (i < 100000) do \ t() \ i = i + 1 \ end \ end \ \ MesureFunc() \ MesureFunc = nil \ "; StartTimer(&timer); luaL_dostring(L, Code); // 运行Lua代码 return GetSeconds(timer) / (double) 100000; }
int Timestamp::Compare(const Timestamp &aCompare) const { uint64_t thisSeconds = GetSeconds(); uint64_t compareSeconds = aCompare.GetSeconds(); uint16_t thisTicks = GetTicks(); uint16_t compareTicks = aCompare.GetTicks(); int rval; if (compareSeconds > thisSeconds) { rval = 1; } else if (compareSeconds < thisSeconds) { rval = -1; } else if (compareTicks > thisTicks) { rval = 1; } else if (compareTicks < thisTicks) { rval = -1; } else { rval = 0; } return rval; }
// ------------------------------------------------------------------------------------------ //! Ticks a frame. GDAPI void IDateTime::OnRuntimeUpdate() { auto const CurrentTime = GetSeconds(); timeFrameDeltaTime = CurrentTime - timeFrameStartTime; timeFrameStartTime = CurrentTime; timeFramesCount++; }
// See KMeans.h Scalar KMeans::RunKMeansPlusPlus(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_clusters, int *ret_assignment) { KM_ASSERT(k >= 1); // Create the tree and log LOG(false, "Running k-means++..." << std::endl); KmTree tree(n, d, points); LOG(false, "Done preprocessing..." << std::endl); // Initialization Scalar *clusters = (Scalar*)malloc(sizeof(Scalar)*k*d); KM_ASSERT(clusters != 0); Scalar min_cost = -1, max_cost = -1, total_cost = 0; double min_time = -1, max_time = -1, total_time = 0; // Run all the attempts for (int attempt = 0; attempt < attempts; attempt++) { double start_time = GetSeconds(); // Choose clusters using k-means++ seeding tree.SeedKMeansPlusPlus(k, clusters); // Run k-means RunKMeansOnce(tree, n, k, d, points, clusters, &min_cost, &max_cost, &total_cost, start_time, &min_time, &max_time, &total_time, ret_clusters, ret_assignment); } LogMetaStats(min_cost, max_cost, total_cost, min_time, max_time, total_time, attempts); // Clean up and return free(clusters); return min_cost; }
void UavReporter::FillMsgEfficiency(MsgEfficiency* tx_msg) { Quaternionf q; q = est->ukf.get_q(); tx_msg->t = GetSeconds(); tx_msg->top_volts = 0; tx_msg->top_amps = 0; tx_msg->top_joules = 0; tx_msg->top_mean = motor_hal->get_top_cmd_volts(); tx_msg->top_speed = motor_hal->get_top_speed(); tx_msg->bottom_volts = 0; tx_msg->bottom_amps = 0; tx_msg->bottom_joules = 0; tx_msg->bottom_mean = motor_hal->get_bottom_cmd_volts(); tx_msg->bottom_speed = motor_hal->get_bottom_speed(); // send quaternion with an implied positive w component if(q.w() >= 0) { tx_msg->qx_est = q.x(); tx_msg->qy_est = q.y(); tx_msg->qz_est = q.z(); } else { tx_msg->qx_est = -q.x(); tx_msg->qy_est = -q.y(); tx_msg->qz_est = -q.z(); } }
// ------------------------------------------------------------------------------------------ //! Returns time in seconds passed till Engine launch as a pretty formatted string. //! @returns Time in seconds passed till Engine launch as a pretty formatted string. GDAPI String IDateTime::GetSecondsString() { auto const QueriedSeconds = GetSeconds(); if (QueriedSeconds < 1.0) { auto const Milliseconds = static_cast<Int32>(QueriedSeconds * 1000.0); return String::Format("%d ms", Milliseconds); } if (QueriedSeconds < 10.0) { auto const Seconds = static_cast<Int32>(QueriedSeconds); auto const Milliseconds = static_cast<Int32>(QueriedSeconds * 1000.0) - Seconds; return String::Format("%d.%02d sec", Seconds, Milliseconds / 10); } if (QueriedSeconds < 60.0) { auto const Seconds = static_cast<Int32>(QueriedSeconds); auto const Milliseconds = static_cast<Int32>(QueriedSeconds * 1000.0) - Seconds; return String::Format("%d.%d sec", Seconds, Milliseconds / 100); } if (QueriedSeconds < 60.0 * 60.0) { auto const Minutes = static_cast<Int32>(QueriedSeconds / 60.0); auto const Seconds = static_cast<Int32>(QueriedSeconds) - (Minutes * 60); return String::Format("%d:%02d min", Minutes, Seconds); } auto const Hours = static_cast<Int32>(QueriedSeconds / (60.0 * 60.0)); auto const Minutes = static_cast<Int32>(QueriedSeconds / 60.0) - (Hours * 60); auto const Seconds = static_cast<Int32>(QueriedSeconds) - (Minutes * 60) - (Hours * 60 * 60); return String::Format("%d:%02d:%02d hours", Hours, Minutes, Seconds); }
std::string MainLoopTimer::GetSecondsString() { std::ostringstream stream; stream.setf(std::ios::fixed | std::ios::showpoint); stream.precision(1); stream << "Elapsed time: " << GetSeconds() << " sec"; return stream.str(); }
std::string MovieSeconds::AsString() const { Seconds curSeconds = GetSeconds(); std::string theString; curSeconds.GetTCString(theString, fTCMode, true); return theString; }
void plTimerShare::SetRealTime(bool realTime) { fRunningFrameTime = !realTime; if (realTime) { fRealSeconds = GetSeconds(); } }
int main(void) { int nDays; int nRecords; int in_hour, in_minute, in_seconds; int out_hour, out_minute, out_seconds; char szName[MAX_SIZE] = {0}; char szEarly[MAX_SIZE] = {0}; char szLater[MAX_SIZE] = {0}; scanf("%d", &nDays); while (nDays--) { int nEarly = 0x3fffffff; int nLater = -1; scanf("%d", &nRecords); for (int i=0; i<nRecords; ++i) { scanf("%s %d:%d:%d %d:%d:%d", szName, &in_hour, &in_minute, &in_seconds, &out_hour, &out_minute, &out_seconds); int checkin = GetSeconds(in_hour, in_minute, in_seconds); if (checkin < nEarly) { nEarly = checkin; //strncpy(szEarly, szName, sizeof(szName)); strcpy(szEarly, szName); } int checkout = GetSeconds(out_hour, out_minute, out_seconds); if (checkout > nLater) { nLater = checkout; //strncpy(szLater, szName, sizeof(szName)); strcpy(szLater, szName); } //printf("****%s %d %d****\n", szName, checkin, checkout); } printf("%s %s\n", szEarly, szLater); }// End of While return 0; }
void UavReporter::FillMsgUavReporterPower(MsgUavReporterPower *tx_msg) { tx_msg->t = GetSeconds(); tx_msg->top_volts = battery->GetVoltsFilt(); tx_msg->top_amps = battery->GetAmpsFilt(); tx_msg->top_joules = battery->GetJoules(); tx_msg->bottom_volts = 0; tx_msg->bottom_amps = 0; tx_msg->bottom_joules = 0; }
/* * int getc(int seconds) * * Reads a character from the DBGU port, if one is available within about * seconds seconds. It assumes that DBGU has already been initialized. */ int getc(int seconds) { AT91PS_USART pUSART = (AT91PS_USART)AT91C_BASE_DBGU; unsigned thisSecond; // Clamp to 20s if (seconds > 20) seconds = 20; thisSecond = GetSeconds(); seconds = thisSecond + seconds; do { if ((pUSART->US_CSR & AT91C_US_RXRDY)) return (pUSART->US_RHR & 0xFF); thisSecond = GetSeconds(); } while (thisSecond != seconds); return (-1); }
CString CSPTimeSpan::Format(LPCTSTR pFormat) const // formatting timespans is a little trickier than formatting CSPTimes // * we are only interested in relative time formats, ie. it is illegal // to format anything dealing with absolute time (i.e. years, months, // day of week, day of year, timezones, ...) // * the only valid formats: // %D - # of days -- NEW !!! // %H - hour in 24 hour format // %M - minute (0-59) // %S - seconds (0-59) // %% - percent sign { TCHAR szBuffer[maxTimeBufferSize]; TCHAR ch; LPTSTR pch = szBuffer; while ((ch = *pFormat++) != '\0') { ASSERT(pch < &szBuffer[maxTimeBufferSize]); if (ch == '%') { switch (ch = *pFormat++) { default: ASSERT(FALSE); // probably a bad format character case '%': *pch++ = ch; break; case 'D': pch += wsprintf(pch, _T("%ld"), GetDays()); break; case 'H': pch += wsprintf(pch, _T("%02d"), GetHours()); break; case 'M': pch += wsprintf(pch, _T("%02d"), GetMinutes()); break; case 'S': pch += wsprintf(pch, _T("%02d"), GetSeconds()); break; } } else { *pch++ = ch; if (_istlead(ch)) { ASSERT(pch < &szBuffer[maxTimeBufferSize]); *pch++ = *pFormat++; } } } *pch = '\0'; return szBuffer; }
/* * .KB_C_FN_DEFINITION_START * int WaitForChar(char *, int) * This global function waits at least the specified number of seconds for * a character and returns non-zero if a character was received and stored in * the pointer. Otherwise, the function returns 0. * .KB_C_FN_DEFINITION_END */ int WaitForChar(char *cPtr, int seconds) { unsigned thisSecond; ++seconds; thisSecond = GetSeconds(); while (seconds) { if (DebugGetchar(cPtr)) { return (1); } if (GetSeconds() != thisSecond) { --seconds; thisSecond = GetSeconds(); } } return (0); }
int main(void) { char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ int len, sec; printf("\nSend data to be written into EEPROM\n"); while ((len = xmodem_rx(addr)) == -1) continue; sec = GetSeconds() + 1; while (sec >= GetSeconds()) continue; printf("\nWriting EEPROM from 0x%x to addr 0, 0x%x bytes\n", addr, len); InitEEPROM(); printf("init done\n"); WriteEEPROM(0, addr, len); printf("\nWrote %d bytes. Press reset\n", len); return (1); }
void SjUptimeWatcher::StopWatching() { wxASSERT( !m_reg.IsEmpty() ); // save new data by calling GetSeconds()... g_tools->m_config->Write(m_reg, GetSeconds()); // ...BEFORE settings m_started to false // (GetSeconds() relies on m_started) m_started = FALSE; }
double Timer::GetMilliSeconds( void) const { #ifdef WIN32 // m_start and m_stop QuadPart returns clock ticks, deviding it by the clock frequency will give clock ticks per second const double miliseconds = SECONDS_TO_MILISECONDS( GetSeconds()); return miliseconds; #endif // default return return 0; }
void CTimer::TotalTime()//输出累计总时间 { _ftime( &timebuffer_end);//获取结束时间 double dEndTime = GetSeconds(timebuffer_end); double dElapsed_time = dEndTime - m_dBeginTime; if(stream == NULL) return; fprintf( stream, m_strTitle + " \nElapsed time :%.4f seconds\n\n",dElapsed_time ); }
void clAudioThread::Run() { if ( !LoadAL() ) { return; } // We should use actual device name if the default does not work FDevice = alcOpenDevice( NULL ); FContext = alcCreateContext( FDevice, NULL ); alcMakeContextCurrent( FContext ); FInitialized = true; FPendingExit = false; double Seconds = GetSeconds(); while ( !IsPendingExit() ) { float DeltaSeconds = static_cast<float>( GetSeconds() - Seconds ); { LMutex Lock( &FMutex ); for ( auto i = FActiveSources.begin(); i != FActiveSources.end(); i++ ) { ( *i )->Update( DeltaSeconds ); } } Seconds = GetSeconds(); Env_Sleep( 100 ); } alcDestroyContext( FContext ); alcCloseDevice( FDevice ); UnloadAL(); }
MovieSeconds MovieSeconds::operator/ (const double inB) const { assert(fInitialized); MovieSeconds outMovieSeconds = *this; Seconds timeInSeconds = GetSeconds(); timeInSeconds = timeInSeconds / inB; outMovieSeconds.Set(timeInSeconds, fVideoRate, fTCMode); return outMovieSeconds; }
int main() { ResetMilli(); bitonic_cpu(data, SIZE); printf("%f\n", GetSeconds()); ResetMilli(); bitonic_gpu(data2, SIZE); printf("%f\n", GetSeconds()); for (int i=0;i<SIZE;i++) if (data[i] != data2[i]) { printf("Error at %d ", i); return(1); } // Print result if (SIZE <= MAXPRINTSIZE) for (int i=0;i<SIZE;i++) printf("%d ", data[i]); printf("\nYour sorting looks correct!\n"); }
void PulsingCoaxControllerQuat::FillMsgYawReport(MsgYawReport* tx_msg) { Vector3f w; w = ukf->ukf.get_w(); tx_msg->t = GetSeconds(); tx_msg->wz_meas = imu->w[2]; tx_msg->wz_est = w(2); tx_msg->wz_filt = pd->w_filt[2]; tx_msg->uz_p = pd->controller.uq(2); tx_msg->uz_d = pd->controller.uw(2); tx_msg->uz_f = pd->uz_f; tx_msg->uz = u.yaw; tx_msg->top_mean = top_mean; tx_msg->bottom_mean = bottom_mean; }
void PulsingCoaxControllerQuat::FillMsgRollReport(MsgRollReport* tx_msg) { Vector3f w; w = ukf->ukf.get_w(); tx_msg->t = GetSeconds(); tx_msg->wx_meas = imu->w[0]; tx_msg->wx_est = w(0); tx_msg->wx_filt = pd->w_filt[0]; tx_msg->ux_p = pd->controller.uq(0); tx_msg->ux_d = pd->controller.uw(0); tx_msg->top_mean = top_mean; tx_msg->bottom_mean = bottom_mean; tx_msg->u_amp = top_pulse_amp; tx_msg->u_phase = u_phase; }
void PulsingCoaxControllerQuat::FillMsgControlCalc(MsgControlCalc* tx_msg) { tx_msg->t = GetSeconds(); tx_msg->ux_p = pd->controller.uq(0); tx_msg->uy_p = pd->controller.uq(1); tx_msg->uz_p = pd->controller.uq(2); tx_msg->ux_d = pd->controller.uw(0);; tx_msg->uy_d = pd->controller.uw(1);; tx_msg->uz_d = pd->controller.uw(2);; tx_msg->uz_f = pd->uz_f; tx_msg->ux_g = pd->ux_g; tx_msg->uy_g = pd->uy_g; tx_msg->thrust_des = thrust_des; tx_msg->u_amp = top_pulse_amp; tx_msg->u_phase = u_phase; }
// See KMeans.h Scalar KMeans::RunKMeans(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_clusters, int *ret_assignment) { KM_ASSERT(k >= 1); // Create the tree and log LOG(false, "Running k-means..." << std::endl); KmTree tree(n, d, points); LOG(false, "Done preprocessing..." << std::endl); // Initialization Scalar *clusters = (Scalar*)malloc(sizeof(Scalar)*k*d); int *unused_clusters = (int*)malloc(sizeof(int)*n); KM_ASSERT(clusters != 0 && unused_clusters != 0); Scalar min_cost = -1, max_cost = -1, total_cost = 0; double min_time = -1, max_time = -1, total_time = 0; // Handle k > n if (k > n) { memset(clusters + n*d, -1, (k-d)*sizeof(Scalar)); k = n; } // Run all the attempts for (int attempt = 0; attempt < attempts; attempt++) { double start_time = GetSeconds(); // Choose clusters uniformly at random for (int i = 0; i < n; i++) unused_clusters[i] = i; int num_unused_clusters = n; for (int i = 0; i < k; i++) { int j = KMeans_GetRandom(num_unused_clusters--); memcpy(clusters + i*d, points + unused_clusters[j]*d, d*sizeof(Scalar)); unused_clusters[j] = unused_clusters[num_unused_clusters]; } // Run k-means RunKMeansOnce(tree, n, k, d, points, clusters, &min_cost, &max_cost, &total_cost, start_time, &min_time, &max_time, &total_time, ret_clusters, ret_assignment); } LogMetaStats(min_cost, max_cost, total_cost, min_time, max_time, total_time, attempts); // Clean up and return free(unused_clusters); free(clusters); return min_cost; }
//开始计时,strTitle为输出的标记。 void CTimer::Tic(CTString strTitle) { _ftime( &timebuffer_begin);//获取起始时间 if(m_bFirst) { m_dBeginTime = GetSeconds(timebuffer_begin); stream = fopen( "../tlAdvn/时间测试.txt", "w" ); if(stream == NULL) return; char* timeline = ctime( & ( timebuffer_begin.time ) ); fprintf( stream,strTitle + " \n时间测试 :%20s \n",timeline ); fprintf( stream," \n*******************测试开始******************\n\n",timeline ); m_bFirst =false; } }