本文整理汇总了C++中WallClockTimer::elapsed方法的典型用法代码示例。如果您正苦于以下问题:C++ WallClockTimer::elapsed方法的具体用法?C++ WallClockTimer::elapsed怎么用?C++ WallClockTimer::elapsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WallClockTimer
的用法示例。
在下文中一共展示了WallClockTimer::elapsed方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testAtan
void testAtan(int N, int rep) {
vector<T> data(N*4);
for (int i = 0; i < 4*N; ++i) {
data[i] = 1 + (rand() % 10000) / 1000.0;
}
WallClockTimer timer;
T sum = 0;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += atan(data[i]);
sum += atan(data[i+1]);
sum += atan(data[i+2]);
sum += atan(data[i+3]);
}
sum /= N*4;
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = rep * N * 4;
cout << "Ignore: " << sum << endl;
cout << "Atans computed: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of Atans per sec: " << (float(TotalQty) / t) << endl;
}
示例2: testIntPowExplicitTemplate
void testIntPowExplicitTemplate(int IntExp, int N, int rep) {
cout << "================================ " << endl;
vector<T> data(N*4);
for (int i = 0; i < 4*N; ++i) {
data[i] = 1 + (rand() % 10000) / 1000.0;
}
WallClockTimer timer;
T sum = 0;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += pow(data[i], (unsigned)IntExp);
sum += pow(data[i+1], (unsigned)IntExp);
sum += pow(data[i+2], (unsigned)IntExp);
sum += pow(data[i+3], (unsigned)IntExp);
}
sum /= N*4;
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = rep * N * 4;
cout << "Ignore: " << sum << endl;
cout << "Pows (expl arguments) computed, degree: " << IntExp << " TotalQty: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of integer Pows (expl arguments) per sec: " << (float(TotalQty) / t) << endl;
}
示例3: testRoot
void testRoot(int N, size_t MaxRoot, int rep) {
vector<T> data(N*4);
for (int i = 0; i < 4*N; ++i) {
data[i] = 1 + (rand() % (10 * MaxRoot)) / 10.0;
}
WallClockTimer timer;
T sum = 0;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += sqrt(data[i]);
sum += sqrt(data[i+1]);
sum += sqrt(data[i+2]);
sum += sqrt(data[i+3]);
}
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = uint64_t(rep) * N * 4LL;
cout << "Ignore: " << sum << endl;
cout << "max root val.: " << MaxRoot << " Roots computed: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of Roots per sec: " << (float(TotalQty) / t) << endl;
}
示例4: testIntPowOptim2
void testIntPowOptim2(int IntExp, int N, int rep) {
cout << "================================ " << endl;
vector<T> data(N*4);
for (int i = 0; i < 4*N; ++i) {
data[i] = 1 + (rand() % 10000) / 1000.0;
}
WallClockTimer timer;
T sum = 0;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += PowOptimPosExp2(data[i], IntExp);
sum += PowOptimPosExp2(data[i+1], IntExp);
sum += PowOptimPosExp2(data[i+2], IntExp);
sum += PowOptimPosExp2(data[i+3], IntExp);
}
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = rep * N * 4;
cout << "Ignore: " << sum << endl;
cout << "Pows (optimized2) computed, degree: " << IntExp << " TotalQty: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of integer (optimized2) Pows per sec: " << (float(TotalQty) / t) << endl;
}
示例5: testPow
void testPow(int N, int rep) {
cout << "================================ " << endl;
vector<T> data1(N*4);
vector<T> data2(N*4);
for (int i = 0; i < 4*N; ++i) {
data1[i] = 1 + (rand() % 10000) / 10.0;
data2[i] = 1 + (rand() % 10000) / 10.0;
}
WallClockTimer timer;
T sum = 0;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += pow(data1[i], data2[i]);
sum += pow(data1[i+1], data2[i+1]);
sum += pow(data1[i+2], data2[i+2]);
sum += pow(data1[i+3], data2[i+3]);
}
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = rep * N * 4;
cout << "Ignore: " << sum << endl;
cout << "Pows computed: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of Pows per sec: " << (float(TotalQty) / t) << endl;
}
示例6: testEfficientFractPow
void testEfficientFractPow(int N, int rep,
unsigned FuncNumDig, unsigned DataNumDig,
bool bRootOnly) {
cout << "================================ " << endl;
vector<T> data1(N*4);
vector<T> data2(N*4);
uint64_t MaxK = uint64_t(1)<<FuncNumDig;
uint64_t DataMaxK = uint64_t(1)<<DataNumDig;
for (int i = 0; i < 4*N; ++i) {
data1[i] = 1 + (rand() % 10000) / 10.0;
data2[i] = bRootOnly ? T(1) / T(DataMaxK):(rand() % MaxK) / T(DataMaxK);
}
WallClockTimer timer;
T sum = 0;
T fract = T(1)/N;
for (int j = 0; j < rep; ++j) {
for (int i = 0; i < N*4; i+=4) {
sum += 0.01 * EfficientFractPow(data1[i], data2[i], FuncNumDig);
sum += 0.01 * EfficientFractPow(data1[i+1], data2[i+1], FuncNumDig);
sum += 0.01 * EfficientFractPow(data1[i+2], data2[i+2], FuncNumDig);
sum += 0.01 * EfficientFractPow(data1[i+3], data2[i+3], FuncNumDig);
}
sum *= fract;
}
timer.split();
uint64_t t = timer.elapsed();
uint64_t TotalQty = rep * N * 4;
cout << "Ignore: " << sum << endl;
cout << "Pows computed: " << TotalQty << ", time " << t / 1e3 << " ms, type: " << typeid(T).name() << endl;
cout << "Milllions of efficient fract Pows (bRootOnly = " << bRootOnly << " per sec: " << (float(TotalQty) / t) << " FuncNumDig = " << FuncNumDig << " DataNumDig = " << DataNumDig << endl;
}
示例7: main
int main(int argc, char * argv[]) {
std::string usage = EXECUTABLE " in LTP " LTP_VERSION " - " LTP_COPYRIGHT "\n";
usage += DESCRIPTION "\n\n";
usage += "usage: ./" EXECUTABLE " <options>\n\n";
usage += "options";
options_description optparser = options_description(usage);
optparser.add_options()
("threads", value<int>(), "The number of threads [default=1].")
("input", value<std::string>(), "The path to the input file. "
"Input data should contain one sentence each line. "
"Words should be separated by space with POS tag appended by "
"'_' (e.g. \"w1_p1 w2_p2 w3_p3 w4_p4\").")
("ner-model", value<std::string>(),
"The path to the postag model [default=ltp_data/ner.model].")
("help,h", "Show help information");
if (argc == 1) {
std::cerr << optparser << std::endl;
return 1;
}
variables_map vm;
store(parse_command_line(argc, argv, optparser), vm);
if (vm.count("help")) {
std::cerr << optparser << std::endl;
return 0;
}
int threads = 1;
if (vm.count("threads")) {
threads = vm["threads"].as<int>();
if (threads < 0) {
std::cerr << "number of threads should not less than 0, reset to 1." << std::endl;
threads = 1;
}
}
std::string input = "";
if (vm.count("input")) { input = vm["input"].as<std::string>(); }
std::string ner_model = "ltp_data/ner.model";
if (vm.count("ner-model")) {
ner_model = vm["ner-model"].as<std::string>();
}
void *engine = ner_create_recognizer(ner_model.c_str());
if (!engine) {
return 1;
}
std::cerr << "TRACE: Model is loaded" << std::endl;
std::cerr << "TRACE: Running " << threads << " thread(s)" << std::endl;
std::ifstream ifs(input.c_str());
std::istream* is = NULL;
if (!ifs.good()) {
std::cerr << "WARN: Cann't open file! use stdin instead." << std::endl;
is = (&std::cin);
} else {
is = (&ifs);
}
Dispatcher * dispatcher = new Dispatcher( engine, (*is), std::cout );
WallClockTimer t;
std::list<tthread::thread *> thread_list;
for (int i = 0; i < threads; ++ i) {
tthread::thread * t = new tthread::thread( multithreaded_recognize, (void *)dispatcher );
thread_list.push_back( t );
}
for (std::list<tthread::thread *>::iterator i = thread_list.begin();
i != thread_list.end(); ++ i) {
tthread::thread * t = *i;
t->join();
delete t;
}
std::cerr << "TRACE: consume " << t.elapsed() << " seconds." << std::endl;
delete dispatcher;
ner_release_recognizer(engine);
return 0;
}
示例8: fillCache
void CurlStreamFile::fillCache(std::streampos size){
#if 1
assert(size >= 0);
if(! _running || _cached >=size){
return ;
}
fd_set readfd, writefd, exceptfd;
int maxfd;
CURLMcode mcode;
timeval tv;
//hard-coded slect timeout
//this number is kept low to give more thread switch
//opportunities while waitting for a load
const long maxSleepUsec = 10000; //1/100 of a second
const unsigned int userTimeout = 60000;
WallClockTimer lastProgress;
while(_running){
fillCacheNonBlocking();
if(_cached>=size || !_running) break;
FD_ZERO(&readfd);
FD_ZERO(&writefd);
FD_ZERO(&exceptfd);
mcode = curl_multi_fdset(_mCurlHandle, &readfd, &writefd,
&exceptfd, &maxfd);
if(mcode != CURLM_OK){
throw SnailException(curl_multi_strerror(mcode));
}
if(maxfd<0){
//as of libcurl 7.21.x, the DNS resolving appears to be
//going on in the background, so curl_multi_fdset fails to
//return anything useful, So we use the user timeout value
//to give DNS enough time to resolve the lookup
if(userTimeout && lastProgress.elapsed()>userTimeout){
return ;
}else{
continue;
}
}//if(maxfd<0)
tv.tv_sec = 0;
tv.tv_usec = maxSleepUsec;
//wait for data on the filedescriptors until a timeout set in rc file
int ret = select(maxfd+1, &readfd, &writefd, &exceptfd, &tv);
#if !defined(WIN32)
if(ret == -1){
if(errno == EINTR){
cout<<"select() was interrupted by a singal"<<endl;
ret = 0;
}else{
std::ostringstream os;
os<<"error polling data from connection to"<<_url<<":"<<strerror(errno);
throw SnailException(os.str());
}
}
#endif
if(!ret){
//timeout check the clock to see
//if we expired the user timeout
if(userTimeout && lastProgress.elapsed() > userTimeout){
cout<<"timeout ("<<userTimeout<<") while loading from URL"<<_url<<endl;
return ;
}
}else{
lastProgress.restart();
}
}//while(....
processMessages();
#endif
}