inline double QwtHighResolutionClock::elapsed() const { struct timespec timeStamp; ::clock_gettime( d_clockId, &timeStamp ); return msecsTo( d_timeStamp, timeStamp ); }
void conjagate_gradients(sp::Vector& dp, const sp::SymetryMatrix& K, const sp::Vector& F) { auto begin_time = QTime::currentTime(); auto r0 = K * dp; r0 -= F; r0 *= -1.0; // r0 := B - A * x auto p = r0; for(int i = 0; i < 1e6; i++) { double a = (r0 * r0) / (p * K * p); dp += a * p; // dp := dp + a * p auto aKp = K * p; aKp *= a; auto r1 = r0 - aKp; // r1 := r0 - a * K * p if(r1 * r1 < 1e-10) { qDebug() << "cgm: counter:\t" << i << "\ttime:\t" << begin_time.msecsTo(QTime::currentTime()); break; } double b = (r1 * r1) / (r0 * r0); p *= b; p += r1; // p := r1 + b * p r0 = r1; } }
int QTime::elapsed() { int n = msecsTo( currentTime() ); if ( n < 0 ) // passed midnight n += 86400*1000; return n; }
int VSTime::restart() { VSTime t = currentTime(); int n = msecsTo(t); if (n < 0) n += 86400*1000; // passed midnight *this = t; return n; }
double QwtHighResolutionClock::restart() { const uint64_t timeStamp = mach_absolute_time(); const double elapsed = msecsTo( d_timeStamp, timeStamp ); d_timeStamp = timeStamp; return elapsed; }
Duration DateTime::duration(const DateTime &dt) const { Duration dur; if (isValid() && dt.isValid()) { qint64 x = msecsTo( dt ); //NOTE: this does conversion to UTC (expensive) dur.m_ms = x < 0 ? -x : x; } //kDebug(planDbg())<<dur.milliseconds(); return dur; }
int QTime::restart() { QTime t = currentTime(); int n = msecsTo( t ); if ( n < 0 ) // passed midnight n += 86400*1000; *this = t; return n; }
double QwtHighResolutionClock::restart() { struct timespec timeStamp; ::clock_gettime( d_clockId, &timeStamp ); const double elapsed = msecsTo( d_timeStamp, timeStamp ); d_timeStamp = timeStamp; return elapsed; }
void run() { // init sp::size = convert::init(pipe::fix_list, point_size); // populate kmx, tmx convert::matrix(pipe::point_list, pipe::element_list, element_size); sp::SymetryMatrix K = convert::kmx; // populate F auto F = convert::force(pipe::force_list, force_size); auto begin_time = QTime::currentTime(); // solve K * dp = F sp::Vector dp; // steepest_descent dp = sp::Vector(); steepest_descent(dp, K, F); Q_ASSERT(sp::Vector::norm2(K * dp, F) < 1e-10); // conjagate_gradients dp = sp::Vector(); conjagate_gradients(dp, K, F); Q_ASSERT(sp::Vector::norm2(K * dp, F) < 1e-10); // solve tensions QVector<double> reaction(3 * point_size - sp::size); sp::mul(reaction, convert::tmx, dp); // convert back to 3D domain convert::displace(displace_list, dp); convert::reaction(reaction_list, pipe::fix_list, fix_size, reaction); QVector<clip::Element> original_elements = clip::make(pipe::point_list, pipe::element_list, element_size, rotate); QVector<clip::Element> displace_elements = clip::make(displace_list, pipe::element_list, element_size, rotate); store_figure_pipe(original_elements, displace_elements); qDebug() << "total time: " << begin_time.msecsTo(QTime::currentTime()); }
void steepest_descent(sp::Vector& dp, const sp::SymetryMatrix& K, const sp::Vector& F) { auto begin_time = QTime::currentTime(); for(int i = 0; i < 1e6; i++) { auto r = K * dp; r -= F; r *= -1.0; // r := F - K * dp if(r * r < 1e-10) { qDebug() << "sdm: counter:\t" << i << "\ttime:\t" << begin_time.msecsTo(QTime::currentTime()); break; } double a = (r * r) / (r * K * r); r *= a; dp += r; // dp := dp + a * r } }
//! Writes line to log file, decorated with information on context and timing. void Logger::log(const QString& lineArg) const { QString line = lineArg; static auto lastTime = startTime_; const auto currTime = QDateTime::currentDateTime(); int tDiff = lastTime.msecsTo(currTime); lastTime = currTime; QString prefix = "["; if (caller_=="gui" && line[0]!='#') { prefix += " "; // direct user action: we don't care how long the user was idle } else { prefix += QString::number(tDiff).rightJustified(5) + "ms"; computingTime_ += tDiff; } prefix += " " + level_ + " " + caller_ + "] "; log_ << prefix << line << "\n"; log_.flush(); if (line.indexOf("##")!=0) { // copy to terminal unless already done by messageHandler qterr << line << "\n"; qterr.flush(); } }
void QGeoInfoThreadWinCE::setUpdateInterval(int interval) { QMutexLocker locker(&mutex); if (interval == updatesInterval) return; int oldInterval = updatesInterval; updatesInterval = interval; if (updatesScheduled) { QDateTime now = currentDateTime(); // The periodic update interval has been changed and updates are still ocurring. if (oldInterval != 0) { if (updatesInterval != 0) { // If we are changing fixed intervals we update the scheduled time for the next // periodic update, making sure that it is scheduled in the future. updatesNextTime = updatesNextTime.addMSecs(updatesInterval - oldInterval); while (msecsTo(now, updatesNextTime) < 0) updatesNextTime = updatesNextTime.addMSecs(updatesInterval); } else { // If we now want to emit updates as the data arrives we invalidate the scheduled // time for the next update, just to be on the safe side. updatesNextTime = now; } } else { // If we were previously emitting updates as the data arrived we set the scheduled time // for the next periodic update. updatesNextTime = now.addMSecs(updatesInterval); } locker.unlock(); wakeUp(); } }
qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return msecsTo(other) / 1000; }
int WTime::secsTo(const WTime& t) const { return msecsTo(t) / 1000; }
qint64 QElapsedTimer::elapsed() const { QElapsedTimer now; now.start(); return msecsTo(now); }
double QwtHighResolutionClock::elapsed() const { return msecsTo( d_timeStamp, mach_absolute_time() ); }
// We try to keep the GPS turned off as much as we can to preserve battery life. // When run() is called we turn on the GPS device and we leave it on // until the request is satisfied or periodic updates are stopped. // The methods requestUpdate() and startUpdates() will call start() if required. void QGeoInfoThreadWinCE::run() { mutex.lock(); gpsReachedOnState = false; m_gps = NULL; const int handleCount = 3; HANDLE handles[handleCount] = { m_newDataEvent, m_gpsStateChange, m_wakeUpEvent }; if (updatesScheduled || requestScheduled) { m_gps = GPSOpenDevice(m_newDataEvent, m_gpsStateChange, NULL, 0); } while (true) { if (stopping) break; if (!updatesScheduled && !requestScheduled) { if (m_gps != NULL) { GPSCloseDevice(m_gps); m_gps = NULL; } statusUpdated.wait(&mutex); if (updatesScheduled || requestScheduled) { gpsReachedOnState = false; m_gps = GPSOpenDevice(m_newDataEvent, m_gpsStateChange, NULL, 0); } } // If the periodic update is 0 then updates are returned as available. // If this is not the case then the next timeout will be set for whichever of // the request and periodic updates that is due next. // We cap the amount of time we spend waiting for updates. DWORD timeout = MaximumMainLoopWaitTime; QDateTime now = currentDateTime(); if (requestScheduled) { if (!updatesScheduled || (updatesInterval == 0) || (msecsTo(requestNextTime, updatesNextTime) >= 0)) { timeout = msecsTo(now, requestNextTime) + 100; } else { if (updatesInterval != 0) timeout = msecsTo(now, updatesNextTime) + 100; } } else { // updatesScheduled has to be true or we wouldn't still be in the larger while loop. if (updatesInterval != 0) timeout = msecsTo(now, updatesNextTime) + 100; } if (timeout > MaximumMainLoopWaitTime) timeout = MaximumMainLoopWaitTime; mutex.unlock(); DWORD dwRet = WaitForMultipleObjects(handleCount, handles, FALSE, timeout); mutex.lock(); // The GPS data has been updated. if (dwRet == WAIT_OBJECT_0) { // The other options are: // dwRet == WAIT_OBJECT_0 + 1 // => The GPS state has been updated. // dwRet == WAIT_OBJECT_0 + 2 // => We called QGeoInfoThreadWinCE::wakeUp(). // dwRet == WAIT_TIMEOUT // => WaitForMultipleObjects() timed out. GPS_POSITION posn; posn.dwVersion = GPS_VERSION_1; posn.dwSize = sizeof(posn); dwRet = GPSGetPosition(m_gps, &posn, timeout, 0); if (dwRet == ERROR_SUCCESS) { if (!validator->valid(posn)) { invalidDataReceived = true; } else { m_lastPosition = posn; hasLastPosition = true; updateTimeoutTriggered = false; // A request and a periodic update could both be satisfied at once. // We use this flag to prevent a double update. bool emitDataUpdated = false; // If a request is in process we emit the dataUpdated signal. if (requestScheduled) { emitDataUpdated = true; requestScheduled = false; } // If we are updating as data becomes available or if the update period has elapsed // we emit the dataUpdated signal. if (updatesScheduled) { QDateTime now = currentDateTime(); if (updatesInterval == 0) { emitDataUpdated = true; } else if (msecsTo(now, updatesNextTime) < 0) { while (msecsTo(now, updatesNextTime) < 0) updatesNextTime = updatesNextTime.addMSecs(updatesInterval); emitDataUpdated = true; } } if (emitDataUpdated) { hasLastPosition = false; mutex.unlock(); emit dataUpdated(m_lastPosition); mutex.lock(); } } } } if (dwRet != WAIT_OBJECT_0 || invalidDataReceived) { invalidDataReceived = false; // Third party apps may have the ability to turn off the gps hardware independently of // the Microsoft GPS API. // This checks for an unexpected power down and turns the hardware back on. // The GPS state has been updated. if (dwRet == WAIT_OBJECT_0 + 1) { GPS_DEVICE device; device.dwVersion = GPS_VERSION_1; device.dwSize = sizeof(device); dwRet = GPSGetDeviceState(&device); if (device.dwDeviceState == SERVICE_STATE_ON) { gpsReachedOnState = true; } else if ((device.dwDeviceState == SERVICE_STATE_OFF) && gpsReachedOnState) { // We do not want to mess with devices that are slow starting up, so we only // turn on devices that have previously reached the "On" state. gpsReachedOnState = false; m_gps = GPSOpenDevice(m_newDataEvent, m_gpsStateChange, NULL, 0); } } // We reach this point if the gps state has changed, if the wake up event has been // triggered, if we received data we were not interested in from the GPS, // or if a timeout occurred while waiting for gps data. // // In all of these cases we should check for request and periodic update timeouts. QDateTime now = currentDateTime(); bool emitUpdateTimeout = false; // Check for request timeouts. if (requestScheduled && msecsTo(now, requestNextTime) < 0) { requestScheduled = false; emitUpdateTimeout = true; } // Check to see if a periodic update is due. if (updatesScheduled && updatesInterval != 0 && (msecsTo(now, updatesNextTime) < 0)) { while (msecsTo(now, updatesNextTime) < 0) updatesNextTime = updatesNextTime.addMSecs(updatesInterval); if (hasLastPosition) { hasLastPosition = false; mutex.unlock(); emit dataUpdated(m_lastPosition); mutex.lock(); } else { if (timeoutsForPeriodicUpdates && !updateTimeoutTriggered) { updateTimeoutTriggered = true; emitUpdateTimeout = true; } } } if (emitUpdateTimeout) { mutex.unlock(); emit updateTimeout(); mutex.lock(); } } } if (m_gps != NULL) GPSCloseDevice(m_gps); mutex.unlock(); }