本文整理汇总了C++中duration类的典型用法代码示例。如果您正苦于以下问题:C++ duration类的具体用法?C++ duration怎么用?C++ duration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了duration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: policyProgressbar
inline std::string policyProgressbar(unsigned const nTotal, unsigned const current = 0){
using namespace std::chrono;
static unsigned maxNTotal = 0;
static unsigned part = 0;
static unsigned tic = 0;
static time_point<steady_clock> startTime;
if(part==0){ startTime = steady_clock::now(); } // get the starting time on the very first call
std::stringstream ss;
auto const now = steady_clock::now();
maxNTotal = std::max(maxNTotal, nTotal);
part = current ? current : part+1;
//limit the update intervall (not faster than every 35ms. This would be madness.)
duration<float> const timeSpent = now - startTime;
if(timeSpent.count() > 0.035f*tic || part == maxNTotal){
++tic;
std::string frame;
unsigned height;
// use all policies to compose a single frame and save its height
std::tie(frame, height) = iteratePolicies<PolicyList...>(part, maxNTotal);
ss << frame;
ss << std::flush;
//move the cursor back to the beginning
if(part!=maxNTotal) ss << "\033[" << height << "A\r";
else ss << "\n";
}
return ss.str();
}
示例2: do_iteration
iteration_stats do_iteration()
{
using namespace boost::chrono;
using boost::make_tuple;
// Zero the counters (to be set during advance() by our slot)
tree_time_ = particle_time_ = 0.0;
particles_visited_ = pparticles_visited_ = 0;
// Get the number of acceleration evals before advancing
const int init_neval = particle_pusher_.num_acceleval();
// Get the current time
const steady_clock::time_point start_time = steady_clock::now();
// Advance the system
particle_pusher_.advance();
// Determine how much time has elapsed
const duration<double> net_push_time = steady_clock::now() - start_time;
// Generate the iteration statistics; see accel_timings_slot
return make_tuple(tree_time_,
particle_time_,
net_push_time.count() - tree_time_ - particle_time_,
particles_visited_,
pparticles_visited_,
particle_pusher_.num_acceleval() - init_neval);
}
示例3: string
std::string mir::logging::input_timestamp(nanoseconds when)
{
// Input events use CLOCK_MONOTONIC, and so we must...
duration<double, std::milli> const age = steady_clock::now().time_since_epoch() - when;
char str[64];
snprintf(str, sizeof str, "%lld (%.6fms ago)",
static_cast<long long>(when.count()),age.count());
return std::string(str);
}
示例4: main
int main(int argc, char * argv[])
{
if (argc != 2)
{
cerr << "Formato " << argv[0] << " <num_elem>" << endl;
return -1;
}
int n = atoi(argv[1]);
int * T = new int[n];
assert(T);
srandom(time(0));
for (int i = 0; i < n; i++)
{
T[i] = random();
};
// escribe_vector(T, n);
tantes = high_resolution_clock::now();
heapsort(T, n);
tdespues = high_resolution_clock::now();
transcurrido = duration_cast<duration<double>>(tdespues - tantes);
cout << n << " "<< transcurrido.count() << endl;
// escribe_vector(T, n);
delete [] T;
return 0;
};
示例5: main
/*
*
* @brief Funcion Principal:
*
*/
int main(int argc, char const *argv[]){
if (argc != 4){
cerr << "Formato " << argv[0] << "<ruta_del_archivo_de_entrada> <num_elem> <num_vect>" << endl;
return -1;
}
int tam_vectores = atoi(argv[2]); //Tamaño vectores
int num_vectores = atoi(argv[3]); //Número vectores
int num = 0;
string ruta=argv[1];
ifstream archivo(ruta.c_str());
// cargamos todos los vectores en una matriz de tipo vector<vector>
matrix vectorAux(num_vectores,tam_vectores);
matrix vectorT (num_vectores, tam_vectores);
vector< vector<int> > vectorRes;
for(int i = 0; i < num_vectores; i++){
for (int j = 0 ; j < tam_vectores; j++){
archivo >> num;
vectorT.datos[i][j] = num;
}
}
tantes = high_resolution_clock::now();
vectorAux = mergeKvectors(vectorT);
tdespues = high_resolution_clock::now();
transcurrido = duration_cast<duration<double>>(tdespues - tantes);
cout << tam_vectores << " "<< transcurrido.count() << endl;
return 0;
}
示例6: to_boost_duration
boost::posix_time::time_duration const
to_boost_duration(
duration<
Rep,
Period
> const &duration_
)
{
BOOST_STATIC_ASSERT(
Period::num == 1
);
return
boost::date_time::subsecond_duration<
boost::posix_time::time_duration,
Period::den
>(
duration_.count()
);
}
示例7:
inline duration<Rep1, Period1> operator % (duration<Rep1, Period1> const & lhs
, duration<Rep2, Period2> const & rhs)
{
return lhs.count() % rhs.count();
}
示例8: printHelpText
int Raw2xBase::run()
{
if (cmdLine.getArgCount() == 0)
{
std::cout << "Not enough arguments!\n";
printHelpText();
return 0;
}
if (cmdLine.hasFlag("h") || cmdLine.hasFlag("help"))
{
printHelpText();
return 0;
}
std::string inFileName, outFileName;
// input_file + output_file
if (cmdLine.getArgCount() >= 2 && cmdLine.getArg(1)[0] != '-') // If arg[1] is not a flag...
{
inFileName = cmdLine.getArg(0);
outFileName = cmdLine.getArg(1);
}
else // Just input_file
{
inFileName = cmdLine.getArg(0);
outFileName.clear();
}
// Replace '.raw' extension of source file with the proper extension
// and use it for the output if no explicit filename was provided.
if (outFileName.empty())
{
outFileName = utils::filesys::removeFilenameExtension(inFileName) + outputFileExt;
}
if (verbose)
{
std::cout << "In file..: " << inFileName << "\n";
std::cout << "Out file.: " << outFileName << "\n";
std::cout << "Options..: " << cmdLine.getFlagsString() << "\n";
}
// We optionally measure execution time.
using namespace std::chrono;
system_clock::time_point t0, t1;
if (timings)
{
t0 = system_clock::now();
}
// Try to open the input file. This might result in an exception.
siege::RawImage rawImage(inFileName);
if (rawImage.getSurfaceCount() > 1 && mipmaps)
{
std::string surfName;
const int surfCount = rawImage.getSurfaceCount();
for (int s = 0; s < surfCount; ++s)
{
surfName = utils::filesys::removeFilenameExtension(outFileName) + "_" + std::to_string(s) + outputFileExt;
writeImageSurf(rawImage, s, surfName, swizzle);
}
}
else // Single image (mipmap 0):
{
writeImageSurf(rawImage, 0, outFileName, swizzle);
}
if (timings)
{
t1 = system_clock::now();
const duration<double> elapsedSeconds(t1 - t0);
const auto endTime = system_clock::to_time_t(t1);
#ifdef _MSC_VER
char timeStr[256];
ctime_s(timeStr, sizeof(timeStr), &endTime);
#else // _MSC_VER
const char * const timeStr = std::ctime(&endTime);
#endif // _MSC_VER
std::cout << "Finished execution on " << timeStr
<< "Elapsed time: " << elapsedSeconds.count() << "s\n";
}
return 0;
}
示例9: f
void f(duration<double> d, double res) // accept floating point seconds
{
// d.count() == 3.e-6 when passed microseconds(3)
BOOST_ASSERT(d.count()==res);
}
示例10: printFormatted
// we've made this function private as it doesn't need to be accessed outside this
// functor. It contains implemenatation details.
void printFormatted( duration<double> elapsed, const string &string )
{
cout << "[LOG ENTRY]: " << elapsed.count() << "s, Entry: " << string << endl;
}
示例11: timeout_t
timeout_t(duration interval, Func&& callback)
: callback(std::forward<Func>(callback)),
id{::SDL_AddTimer(interval.count(), run_callback, this)} {
SDLXX_CHECK(id != 0);
}
示例12: duration_cast
To duration_cast(duration const& d) {
rational dstr(To::period::num, To::period::den);
rational tr = d.ratio() / dstr;
return To(tr.numerator() / tr.denominator());
}
示例13: segmentImage
std::vector<cv::Mat> HierClassifier::classify(cv::Mat image,
cv::Mat terrain,
cv::Mat segmentation,
cv::Mat maskIgnore,
int entryWeightThreshold)
{
Mat regionsOnImage;
if(segmentation.empty()){
regionsOnImage = segmentImage(image);
}
else{
regionsOnImage = segmentation;
}
vector<Entry> entries = extractEntries(image,
terrain,
regionsOnImage,
maskIgnore,
entryWeightThreshold);
using namespace std::chrono;
high_resolution_clock::time_point start = high_resolution_clock::now();
high_resolution_clock::time_point end;
//ofstream log("descriptors");
//for(int e = 0; e < entries.size(); e++){
// log << entries[e].descriptor << endl;
//}
map<int, int> imageIdToEntry;
for(int e = 0; e < entries.size(); e++){
imageIdToEntry[entries[e].imageId] = e;
}
Mat result(entries.size(), numLabels, CV_32FC1, Scalar(0));
for(int c = 0; c < classifiers.size(); c++){
//cout << "Classifing using classifier " << c << endl;
for(int e = 0; e < entries.size(); e++){
//cout << "classInfo.descBeg = " << classifiersInfo[c].descBeg << ", descEnd = " << classifiersInfo[c].descEnd << endl;
//cout << "descriptor.numCols = " << entries[e].descriptor.cols << endl;
Mat desc = entries[e].descriptor.colRange(
classifiersInfo[c].descBeg,
classifiersInfo[c].descEnd);
//cout << "result, entry " << e << ", " << weights[c]*classifiers[c]->classify(desc) << endl;
result.row(e) = result.row(e) + weights[c]*classifiers[c]->classify(desc);
}
}
vector<Mat> ret;
ret.resize(numLabels);
for(int l = 0; l < numLabels; l++){
ret[l] = Mat(image.rows, image.cols, CV_32FC1, Scalar(-2));
}
for(int l = 0; l < numLabels; l++){
for(int r = 0; r < image.rows; r++){
for(int c = 0; c < image.cols; c++){
if(imageIdToEntry.count(regionsOnImage.at<int>(r, c)) > 0){
ret[l].at<float>(r, c) = result.at<float>(imageIdToEntry[regionsOnImage.at<int>(r, c)], l);
}
}
}
}
end = high_resolution_clock::now();
static duration<double> compTime = duration<double>::zero();
static int times = 0;
compTime += duration_cast<duration<double> >(end - start);
times++;
if(debugLevel >= 1){
cout << "Classify Times: " << times << endl;
cout << "Classify Average computing time: " << compTime.count()/times << endl;
}
return ret;
}
示例14: physics_function
void physics_function(duration<double> d)
{
std::cout << "d = " << d.count() << '\n';
}
示例15: timeout
void reactor::timeout(duration timeout) {
if (timeout == duration::FOREVER || timeout.milliseconds() > PN_MILLIS_MAX)
pn_reactor_set_timeout(pn_object(), PN_MILLIS_MAX);
else
pn_reactor_set_timeout(pn_object(), timeout.milliseconds());
}