本文整理汇总了C++中Chrono类的典型用法代码示例。如果您正苦于以下问题:C++ Chrono类的具体用法?C++ Chrono怎么用?C++ Chrono使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Chrono类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
Chrono ch;
Timer tm;
ch.startChrono();
fstream logfile;
logfile.open("results_knapsack.txt", ios::out);
//remember the limit of the 4gb allocated space
int dim[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
int local_threads[] = {0, 64, 128, 256, 512, 1024};
for (int k = 5; k < sizeof (local_threads) / sizeof (int); k++) {//local_threads
for (int j = 9; j < sizeof (dim) / sizeof (int); j++) {
TestData* test = new TestData(dim[j]);
Knapsack *ksack = new Knapsack(*test);
//1.Query the host system for OpenCL platform info
ksack->queryOclPlatformInfo(&logfile);
//2. Query the host for OpenCL devices
ksack->queryOclDevice(&logfile);
for (int i = 0; i < ksack->getNumDevices(); i++) {
ksack->queryOclDeviceInfo(i, &logfile);
//3. Create a context and a queue to associate the OpenCL devices.
ksack->createContextQueue(i, &logfile);
//4. Create programs that will run on one or more associated devices.
ksack->createProgramBuild(i, &logfile);
//5. Create memory objects on the host or on the device.
//6. Copy memory data to the device as needed. Create memory objects on the host or on the device.
ksack->createMemObjects(&logfile);
//7. Create Kernels
ksack->createKernel();
//8. Provide arguments for the kernels.
// ksack.createKernel();
//9. Submit the kernels to the command queue for execution.
//10. Copy the results from the device to the host
//ksack.executeMemObjects();
ksack->executeComputation(i, &logfile, local_threads[k]);
ksack->printResults(&logfile);
}
delete ksack;
delete test;
}
}
logfile.close();
//http://stackoverflow.com/questions/14063791/double-free-or-corruption-but-why
ch.stopChrono();
tm.stop();
cout << "CHRONO TIME: " << ch.getTimeChrono() << endl;
cout << "TIMER TIME: " << tm.getTime();
return 0;
}
示例2: TEST
TEST(Test1, pngWriteDataToMemory) {
std::cout << "########## Image memory write" << std::endl;
PngReader pngReaderFromFile;
FilePngInputStream filePngInputStream(IMAGE1);
pngReaderFromFile.readFromInputstream(filePngInputStream);
Chrono chrono;
PngData pngData(pngReaderFromFile.getWidth(), pngReaderFromFile.getHeight(),
pngReaderFromFile.getBitDepth(), pngReaderFromFile.getColorType(),
pngReaderFromFile.getPixelDataRowPointers());
PngWriter writer(pngData);
MemoryPngOutputStream memOs;
writer.writePngToOutputStream(memOs);
std::cout << "Image write png to memory in " << chrono.elapsedTimeInMs()
<< " ms, nrOfBytes=" << memOs.getNrOfBytes() << std::endl;
// Read the data written to memory, and check against the original
MemoryPngInputStream memoryInputstream(memOs.getBuffer().data(),
memOs.getNrOfBytes());
PngReader pngReaderFromMemory;
pngReaderFromMemory.readFromInputstream(memoryInputstream);
AssertUtil::equals(pngReaderFromFile, pngReaderFromMemory);
}
示例3: main
int main(void){
Chrono c;
c.start();
int sum = 1,
step = 2,
diagonalcount = 0,
previousdiagonal = 1,
dimension = 1001;
while(previousdiagonal < (dimension * dimension)){
if(diagonalcount == 4){
diagonalcount = 0;
step += 2;
}
int to_add = previousdiagonal + step;
sum += to_add;
previousdiagonal = to_add;
diagonalcount++;
}
c.stop();
std::cout << "The sum of the numbers on the diagonals in a " << dimension << " by " << dimension << " spiral is " << sum << std::endl;
std::cout << "Found the answer in " << c.time() << " seconds" << std::endl;
return 0;
}
示例4: test_with_ctor
void test_with_ctor()
{
double msecs = 0.0;
int c = 0;
for (; c<10000; ++c) {
Chrono chrono;
std::sin(0.0);
msecs += chrono.elapsed();
}
std::cout << "sin(0) in " << (msecs/c) << " milliseconds (average from " << c << " runs)\n";
}
示例5: update
void Game::update()
{
Chrono updateTiming;
m_state.update();
m_view.setCenter((m_state.getObjects().getPlayer().getPosition())/VIEW_DELAY_FACTOR);
m_userInterface.update(m_state);
m_userInterface.setUpdateTime(updateTiming.get());
}
示例6: sorteertijd
double sorteertijd(vector<T> &v, SorteerMethode<T>* methode, int ncycli=1){
double somTijden = 0.0;
for (int i = 0; i < ncycli; i++){
vector<T> kopie (v);
Chrono c;
c.start();
(*methode)(kopie);
c.stop();
somTijden += c.tijd();
}
return somTijden / ncycli;
}
示例7: main
int main(int argc, char **argv) {
if (argc < 2) {
std::cout << "Usage: pgn-app png-in" << std::endl;
return 1;
}
Chrono chrono;
chrono.reset();
IOUtils png;
png.readFile(argv[1]);
MemoryPngInputStream memoryInputstream((const png_bytep) png.getBuffer(),
(const png_size_t) png.getLength());
std::cout << "Image read info memory in " << chrono.elapsedTimeInMs()
<< " ms" << std::endl;
{
chrono.reset();
PngReader rdrMem;
memoryInputstream.reset();
rdrMem.readFromInputstream(memoryInputstream, true);
std::cout << "Image read memory (own alloc)in "
<< chrono.elapsedTimeInMs() << " ms" << std::endl;
}
chrono.reset();
PngReader rdrMem;
memoryInputstream.reset();
rdrMem.readFromInputstream(memoryInputstream);
std::cout << "Image read memory (pnglib alloc) in "
<< chrono.elapsedTimeInMs() << " ms" << std::endl;
PngData pngData(rdrMem.getWidth(), rdrMem.getHeight(), rdrMem.getBitDepth(),
rdrMem.getColorType(), rdrMem.getPixelDataRowPointers());
std::cout << "Nr of bytes pixelData=" << pngData.getNrOfBytesPixelData()
<< std::endl;
// Loop to see if having a preallocated buffer works better. Answer: yes
// Saving was 0-20 ms (on VM on Laptop: (windows7,[email protected] ghz, 8gb)
const uint32_t estimatedPngHeaderSize = 1024 * 8;
for (int j = 0; j < 10; j++) {
for (uint32_t i = 0; i < 2; i++) {
uint32_t outputBufferSize = pngData.getNrOfBytesPixelData()
+ estimatedPngHeaderSize;
MemoryPngOutputStream memOs(i * outputBufferSize);
chrono.reset();
PngWriter writer(pngData);
writer.writePngToOutputStream(memOs);
std::cout << "Iteration: " << i << ", image write png to memory in "
<< chrono.elapsedTimeInMs() << " ms and has size "
<< memOs.getNrOfBytes() << " bytes" << std::endl;
}
}
return 0;
}
示例8: InitModels
void MyGLWindow::InitModels()
{
Chrono chrono;
// load models
ModelLoader modelLoader;
chrono.start();
_actorLib["Tank"] = modelLoader.LoadFromFile("./data/model/stankbot/models/stankbot.dae");
_actorLib["Tank"]->SetShaderProgram(_shaderProgLib["defaultShader"]);
std::cout << "Load stankbot (ms) : " << chrono.ellapsed() << std::endl;
chrono.start();
_actorLib["Dragon"] = modelLoader.LoadFromFile("./data/model/dragon_vrip_res3.ply");
_actorLib["Dragon"]->SetShaderProgram(_shaderProgLib["defaultShader"]);
std::cout << "Load dragon (ms) : " << chrono.ellapsed() << std::endl;
}
示例9: render
void Game::render()
{
Chrono drawTiming;
m_targetWindow.clear(sf::Color::Black);
m_targetWindow.setView(m_view);
m_state.getObjects().draw(m_targetWindow);
m_state.getBorders().draw(m_targetWindow);
m_targetWindow.setView(m_targetWindow.getDefaultView());
m_userInterface.draw(m_targetWindow);
m_targetWindow.display();
m_userInterface.setDrawTime(drawTiming.get());
}
示例10: main
int main(int argc, char *argv[])
{
srand(time(0));
Sortvector<int> temp(10);
temp.shuffle();
//Start het hele sorteer-circus
Chrono chr;
cout<<"Insertion sort"<<endl;
vector<int> vec1 = temp;
InsertionSort<int> ins_sort;
chr.start();
ins_sort(vec1);
chr.stop();
cout<<"Insertion sort duurde "<<chr.tijd()<<"."<<endl;
cout<<"STL sort"<<endl;
vec1 = temp;
STLSort<int> stl_sort;
chr.start();
stl_sort(vec1);
chr.stop();
cout<<"Insertion sort duurde "<<chr.tijd()<<"."<<endl;
return 0;
}
示例11: waitForMessage
void ClientInterface::waitForMessage(){
Chrono chrono;
chrono.start();
while(getNextMessageType()==nmtInvalid){
if(!isConnected()){
throw runtime_error("Disconnected");
}
if(chrono.getMillis()>messageWaitTimeout){
throw runtime_error("Timeout waiting for message");
}
sleep(waitSleepTime);
}
}
示例12: waitUntilReady
void ClientInterface::waitUntilReady(Checksum* checksum){
NetworkMessageReady networkMessageReady;
Chrono chrono;
chrono.start();
//send ready message
sendMessage(&networkMessageReady);
//wait until we get a ready message from the server
while(true){
NetworkMessageType networkMessageType= getNextMessageType();
if(networkMessageType==nmtReady){
if(receiveMessage(&networkMessageReady)){
break;
}
}
else if(networkMessageType==nmtInvalid){
if(chrono.getMillis()>readyWaitTimeout){
throw runtime_error("Timeout waiting for server");
}
}
else{
throw runtime_error("Unexpected network message: " + intToStr(networkMessageType) );
}
// sleep a bit
sleep(waitSleepTime);
}
//check checksum
if(Config::getInstance().getBool("NetworkConsistencyChecks")){
if(networkMessageReady.getChecksum()!=checksum->getSum()){
throw runtime_error("Checksum error, you don't have the same data as the server");
}
}
//delay the start a bit, so clients have nore room to get messages
sleep(GameConstants::networkExtraLatency);
}
示例13: main
int main(int argc, char **argv) {
Random rand; // default constructor seeds with 0
fixed fixed_numbers[NUM_TRIALS];
fixed fixed_roots[NUM_TRIALS];
float float_numbers[NUM_TRIALS];
float float_roots[NUM_TRIALS];
for (int i=0; i < NUM_TRIALS; ++i) {
fixed_numbers[i] = rand.randRange(4, 4000);
fixed_numbers[i] += rand.randRange(0, 4095) / fixed(4096);
float_numbers[i] = fixed_numbers[i].toFloat();
}
{ // using floats and sqrtf(), for reference
Chrono chrono;
chrono.start();
for (int i=0; i < NUM_TRIALS; ++i) {
float_roots[i] = sqrtf(float_numbers[i]);
}
chrono.stop();
cout << "\nDone, " << NUM_TRIALS << " floating point square roots. Took " << chrono.getMicros() << "us";
}
DO_TEST(sqRt_c);
DO_TEST(sqRt_unrolled_once);
DO_TEST(sqRt_unrolled_twice);
DO_TEST(sqRt_unrolled_thrice);
DO_TEST(sqRt_unrolled_completely);
DO_TEST(sqRt_julery);
DO_TEST(sqRt_julery_crowne);
cout << "\n\n[Enter]";
char boo[8];
std::cin.getline(boo, 8);
}
示例14: SetValue
void xPLCron::SetValue(Chrono& chrono, const string& value)
{
xPL::SchemaControlBasic sendCmnd;
string moduleName;
string deviceName;
string deviceType;
LOG_ENTER;
moduleName = chrono.GetModuleName();
deviceName = chrono.GetDeviceName();
deviceType = chrono.GetDeviceType();
chrono.SetValue(value);
sendCmnd.SetDeviceType(deviceType);
sendCmnd.SetDeviceName(deviceName);
sendCmnd.SetCurrent(value);
LOG_VERBOSE(m_Log) << "Send " << value << " to " << moduleName << " device " << deviceName;
m_xPLDevice.SendMessage(&sendCmnd, moduleName);
LOG_EXIT_OK;
}
示例15: launch_bench_square
void launch_bench_square(Field & F // const problem
, size_t min, size_t max, size_t step // no negative step
, PlotData & Data
)
{
linbox_check(step);
linbox_check(min <= max);
std::ostringstream nam ;
F.write(nam);
// Data.setCurrentSeriesName(nam.str());
Data.newSeries(nam.str());
Chrono<Timer> TW ;
typedef typename Field::RandIter Randiter ;
Randiter R(F) ;
BlasMatrixDomain<Field> BMD(F) ;
RandomDenseMatrix<Randiter,Field> RandMat(F,R);
for ( size_t i = min ; i < max ; i += step ) {
showAdvanceLinear(i,min,max);
size_t ii = i ;
BlasMatrix<Field> A (F,ii,ii);
BlasMatrix<Field> B (F,ii,ii);
BlasMatrix<Field> C (F,ii,ii);
size_t j = 0 ; // number of repets.
RandMat.random(A);
RandMat.random(B);
RandMat.random(C);
TW.clear() ;
while( Data.keepon(j,TW.time(),false) ) {
TW.start() ;
BMD.mul(C,A,B) ; // C = AB
TW.stop();
++j ;
}
double mflops = computeMFLOPS(TW.times(),mm_mflops(i,i,i));
Data.setCurrentSeriesEntry(i,mflops,(double)i,TW.time()); // could be i*i*i
}
Data.finishSeries();
}