当前位置: 首页>>代码示例>>C++>>正文


C++ WallClockTimer类代码示例

本文整理汇总了C++中WallClockTimer的典型用法代码示例。如果您正苦于以下问题:C++ WallClockTimer类的具体用法?C++ WallClockTimer怎么用?C++ WallClockTimer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WallClockTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
    
}
开发者ID:Maxime2,项目名称:TestsCPP,代码行数:28,代码来源:testpow.cpp

示例2: 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;

}
开发者ID:searchivarius,项目名称:BlogCode,代码行数:26,代码来源:testtrigon.cpp

示例3: test3

void test3(int N, int rep) {
  WallClockTimer timer;

  uint64_t total = 0;

  uint64_t sum = 0;

  string       emptyStr;
  stringstream str;

  for (int j = 0; j < rep; ++j) {

    timer.reset();

    for (int i = 0; i < N; i++) {
      str.str(emptyStr);
      str << i << " " << j; 
      sum += reinterpret_cast<size_t>(str.str().c_str());
    }

    total += timer.split();
  }

  cout << "Ignore: " << sum << endl;
  cout << " total # of proc without construct/deconstruct: " << rep * N << ", time " <<  total / 1e3 << " ms" << " proc per sec: " << (rep * N * 1e6 / total ) << endl;
}
开发者ID:searchivarius,项目名称:BlogCode,代码行数:26,代码来源:teststringstream.cpp

示例4: 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;
    
}
开发者ID:alepharchives,项目名称:TestsCPP,代码行数:25,代码来源:testroot.cpp

示例5: 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;
    
}
开发者ID:searchivarius,项目名称:BlogCode,代码行数:27,代码来源:testpow.cpp

示例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;
    
}
开发者ID:searchivarius,项目名称:BlogCode,代码行数:35,代码来源:testfractpow.cpp

示例7: 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;
    
}
开发者ID:Maxime2,项目名称:TestsCPP,代码行数:26,代码来源:testpow.cpp

示例8: test

void test(size_t N ) {
    WallClockTimer time;
    for(int t = 0; t<2;++t) {
      cout <<" test # "<< t<<endl;
      vector<short> data = givemeanarray(N) ;
      vector<short> copydata(data);
      
      time.reset();
      straightsum(&data[0],N);
      cout<<"straight sum (C-like) "<<N/(1000.0*time.split())<<endl;   
      
 
      time.reset();
      slowishSum(data);
      cout<<"basic sum (C++-like) "<<N/(1000.0*time.split())<<endl;   
      
      data = copydata;

      time.reset();
      sum(data);
      cout<<"smarter sum "<<N/(1000.0*time.split())<<endl;   
 
      data = copydata;

      time.reset();
      fastSum(data);
      cout<<"fast sum "<<N/(1000.0*time.split())<<endl;   
 
      cout<<endl<<endl<<endl;

    }

}
开发者ID:alepharchives,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:33,代码来源:cumulsums.cpp

示例9: overall

int overall(size_t N) {
	int bogus = 0;
	WallClockTimer t;
	t.reset();
    bogus += testSTL(N);
    int delay = t.split();
    cout << "STL vector " << N /(delay * 1000.0) << endl;
    vector<double> idelays;
    for(size_t T = 0 ; T < 20 ; ++T ) {
          t.reset();
    	  bogus += straight(N);
    	  int tdelay = t.split();
    	  idelays.push_back(tdelay);
    }
    cout << "static array : " << N /(median(idelays) * 1000.0) << endl;
    for(size_t factor = 1; factor <= 6; ++ factor) {
        vector<double> delays;
        for(size_t T = 0 ; T < 20 ; ++T ) {
          t.reset();
    	  bogus += testManual(N,2+factor,2);
    	  int tdelay = t.split();
    	  delays.push_back(tdelay);
        }
    	cout << "pointer-based "<< (factor +2)/2.0<< " : " << N /(median(delays) * 1000.0) << endl;
    }
    return bogus;
}
开发者ID:alepharchives,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:27,代码来源:dynarray.cpp

示例10: test

int test(const size_t N) {
	int *  a = new int[N];
	for(size_t k = 0; k< N; ++k)
	  a[k] = k - 2 + k * k;
	int fakecounter = 0;
	cout<<" Buffer size = "<< N*sizeof(int) /(1024.0*1024.0)<<" MB "<<endl;

	WallClockTimer t;
	double besttime1 = numeric_limits<double>::max();
	double besttime2 = numeric_limits<double>::max();
	double besttime3 = numeric_limits<double>::max();
	for(int k = 0; k<20;++k) {
		t.reset();
		fakecounter += totalsum(a,N);
		double thistime1 = t.split();
		if(thistime1 < besttime1) besttime1 = thistime1;
		t.reset();
		fakecounter += sum<2>(a,N);
		double thistime2 = t.split();
		if(thistime2 < besttime2) besttime2 = thistime2;
		t.reset();
		fakecounter += sum<16>(a,N);
		double thistime3 = t.split();
		if(thistime3 < besttime3) besttime3 = thistime3;
	}
    cout<<" total sum speed = "<<N/(1000*1000*besttime1) <<" mis or "<< N*sizeof(int)/(1024.0*1024.0*besttime1)<<" MB/s"<<endl;
    cout<<" partial sum speed = "<<N/(1000*1000*besttime2) <<" mis or "<< N*sizeof(int)/(1024.0*1024.0*besttime2)<<" MB/s"<<endl;
    cout<<" speed ratio = "<< besttime1 /besttime2<<endl;
    cout<<" partial sum speed = "<<N/(1000*1000*besttime3) <<" mis or "<< N*sizeof(int)/(1024.0*1024.0*besttime3)<<" MB/s"<<endl;
    cout<<" speed ratio = "<< besttime1 /besttime3<<endl;
    return fakecounter;
}
开发者ID:KWillets,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:32,代码来源:elazartest.cpp

示例11: testPackUnpackC

void testPackUnpackC(size_t N =  2048 * 32 * 2048) {
	WallClockTimer timer;
	bool* data = new bool[N];
	for(size_t i = 0; i<N; ++i)
	  data[i] = static_cast<bool>(i & 1);
	vector<char> comp(N/8);
	for(size_t t = 0; t< 3; ++t) {
		timer.reset();
		pack(data, &comp[0], N);
		cout<<" pack time = "<<timer.split()<<endl;
		timer.reset();
		unpack(&comp[0], data, N);
		cout<<" unpack time = "<<timer.split()<<endl;
		for(size_t i = 0; i<N; ++i) 
			assert(data[i] == static_cast<bool>(i & 1));	  
	}
	delete[] data;
}
开发者ID:alepharchives,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:18,代码来源:storeload.cpp

示例12: testStoreLoadC

int testStoreLoadC(size_t M =  2048 * 4, size_t N = 2048 * 8, size_t repeat = 1) {
	WallClockTimer timer;
	vector<int> data;
	int bogus;
	for(size_t i = 0; i<M; ++i)
	  data.push_back(i);
	vector<int> bigdata;
	bigdata.resize(M * N);
	for(size_t t = 0; t< 3; ++t) {
		timer.reset();
		for (size_t r = 0; r < repeat; ++r)
			bogus += storeTestC(&data[0],&bigdata[0],N,M);
		if(t>0) cout<<" store time = "<<timer.split()<<endl;
		timer.reset();
		for (size_t r = 0; r < repeat; ++r)
	    	bogus += loadTestC(&data[0],&bigdata[0],N,M);
		if(t>0) cout<<" load time = "<<timer.split()<<endl;
		for(int i = 0; i<M; ++i)
	  		assert(data[i] == i);
	}
    return bogus;
}
开发者ID:alepharchives,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:22,代码来源:storeload.cpp

示例13: test

void test(size_t N ) {
    cout << "min distance between ints is "<<mindist<<endl;
    WallClockTimer time;
    for(int t = 0; t<2;++t) {
      cout <<" test # "<< t<<endl;
      vector<int> data = givemeanarray(N) ;
      vector<int> copydata(data);
      
      time.reset();
      cdelta<mindist>(&data[0],data.size());
      cout<<"c delta speed "<<N/(1000.0*time.split())<<endl;   
      time.reset();
      cinverseDelta<mindist>(&data[0],data.size());
      cout<<"c inverse delta speed "<<N/(1000.0*time.split())<<endl;   
      if(data != copydata) throw runtime_error("bug!");
      cout<<endl;
 
      time.reset();
      delta<mindist>(data);
      cout<<"delta speed "<<N/(1000.0*time.split())<<endl;   
      time.reset();
      inverseDelta<mindist>(data);
      cout<<"inverse delta speed "<<N/(1000.0*time.split())<<endl;   
      if(data != copydata) throw runtime_error("bug!");
      cout<<endl;


      delta<mindist>(data);
      time.reset();
      slowishinverseDelta<mindist>(data);
      cout<<"slowish inverse delta speed "<<N/(1000.0*time.split())<<endl;   
      if(data != copydata) throw runtime_error("bug!");
      cout<<endl;

      delta<mindist>(data);
      time.reset();
      bufferedinverseDelta<mindist>(data);
      cout<<"buffered inverse delta speed "<<N/(1000.0*time.split())<<endl;   
      if(data != copydata) throw runtime_error("bug!");
      cout<<endl;


      delta<mindist>(data);
      time.reset();
      inverseDeltaVolkov<mindist>(data);
      cout<<"inverse delta speed (volkov-lemire) "<<N/(1000.0*time.split())<<endl;   
      if(data != copydata) throw runtime_error("bug!");
      cout<<endl;


      cout<<endl<<endl<<endl;
    }

}
开发者ID:alepharchives,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:54,代码来源:unrolldeltas.cpp

示例14: 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;
}
开发者ID:Chengtianxiang,项目名称:ltp,代码行数:85,代码来源:ner_cmdline.cpp

示例15: main

int main() {
    assert(sizeof(long)==8);
    assert(sizeof(int)==4);
    WallClockTimer timer;
    int repeat = 100;
    int N = 10000;
    cout<<"# We report bits-per-integer speed-of-naive speed-of-popcnt1 speed-of-popcnt2 speed-of-table speed-of-tzcnt1 speed-of-tzcnt2 where speeds are in millions of integers per second "<<endl;
    for(int sb = 1; sb<=64; sb*=2) {
        int setbitsmax = sb*N;
        vector<long> bitmap(N);
        for (int k = 0; k < setbitsmax; ++k) {
            int bit = rand() % (N*64);
            bitmap[bit/64] |= (1L<<(bit%64));
        }
        int bitcount = 0;
        for(int k = 0; k <N; ++k) {
            bitcount += __builtin_popcountl(bitmap[k]);
        }
        double bitsperinteger = N*sizeof(long)*8.0/bitcount;
        vector<int> outputnaive(bitcount);
        vector<int> outputpopcnt1(bitcount);
        vector<int> outputpopcnt2(bitcount);
        vector<int> outputtable(bitcount);
        vector<int> outputctz1(bitcount);
        vector<int> outputctz2(bitcount);
        cout<<"# Stored "<<bitcount<<" unary numbers in  ";
        cout<< N*sizeof(long)<<" bytes " ;
        cout<<" ("<<bitsperinteger<<" bits per number)"<<endl;
        timer.reset();
        int c0 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c0 = bitscanunary_naive(bitmap.data(),N,outputnaive.data());
        int tinaive = timer.split();
        timer.reset();
        int c1 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c1 = bitscanunary_popcnt1(bitmap.data(),N,outputpopcnt1.data());
        assert(c1 == c0);
        int tipopcnt1 = timer.split();
        timer.reset();
        int c12 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c12 = bitscanunary_popcnt2(bitmap.data(),N,outputpopcnt2.data());
        assert(c12 == c0);
        int tipopcnt2 = timer.split();
        timer.reset();
        int c2 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c2 = bitscanunary_table(bitmap.data(),N,outputtable.data());
        assert(c2 == c0);
        int titable = timer.split();
        timer.reset();
        int c3 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c3 = bitscanunary_ctzl1(bitmap.data(),N,outputctz1.data());
        assert(c3 == c0);
        int tictz1 = timer.split();
        timer.reset();
        int c32 = 0;
        for(int t1=0; t1<repeat; ++t1)
            c32 = bitscanunary_ctzl2(bitmap.data(),N,outputctz2.data());
        assert(c32 == c0);
        int tictz2 = timer.split();

        assert (outputnaive == outputpopcnt1);
        assert (outputnaive == outputpopcnt2);
        assert (outputnaive == outputtable);
        assert (outputnaive == outputctz1);
        assert (outputnaive == outputctz2);        
        cout << bitsperinteger<<" " ;
        cout << bitcount * repeat * 0.001 /tinaive <<" ";
        cout << bitcount * repeat * 0.001 /tipopcnt1 <<" ";
        cout << bitcount * repeat * 0.001 /tipopcnt2 <<" ";
        cout << bitcount * repeat * 0.001 /titable <<" ";
        cout << bitcount * repeat * 0.001 /tictz1 <<" ";
        cout << bitcount * repeat * 0.001 /tictz2 <<" ";
        cout << endl ;
    }

    return 0;
}
开发者ID:blue119,项目名称:Code-used-on-Daniel-Lemire-s-blog,代码行数:81,代码来源:unarydecoding.cpp


注:本文中的WallClockTimer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。