Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

CPP

Name: Anonymous 2011-11-27 10:04

Hi,

is it a good practice to write this #def in cpp?

#define print(X) std::cout<<X<<std::endl

so that it can be used as:

print("what " << "ever" << " I " << "want");

btw.. how do I insert sniplet of code here?

Name: Anonymous 2011-11-27 10:41

btw:

printf:0.019151s cout:0.01957s

with this program:



#include <iostream>
#include <ctime>

int main (int argc, char * const argv[]) {
    clock_t cstart,cend,cppstart,cppend;
   
    cstart = clock();
    for (int i =0; i < 10000; ++i) {
        printf("Hello World\n");
    }
    cend = clock();
    double diff_c = cend/(float)CLOCKS_PER_SEC - cstart/(float)CLOCKS_PER_SEC;
   
    cppstart = clock();
    for (int i = 0; i<10000; ++i) {
        std::cout<<"Hello World\n";
    }
    cppend = clock();
   
    double diff_cpp = cppend/(float)CLOCKS_PER_SEC - cppstart/(float)CLOCKS_PER_SEC;
   
    std::cout<< "c:" << diff_c << "cpp:" << diff_cpp<< std::endl;
    std::cout<< std::endl;
    return 0;
}

Name: Anonymous 2011-11-27 10:46

>>19
http://www2.research.att.com/~bs/hopl2.pdf
Jerry Schwarz reimplemented and partially redesigned the
streams library

You weren't joking.

Name: Anonymous 2011-11-27 10:49

>>20
std::time only has millisecond resolution, nor is it guaranteed to be monotonic. You can't use it for serious timing.

If you're on a POSIX system, use clock_gettime with CLOCK_CLOCK_THREAD_CPUTIME_ID, which has accurate monotonic nanosecond resolution time for the calling thread, and doesn't take into account process/thread context switching.

http://linux.die.net/man/3/clock_gettime

Name: Anonymous 2011-11-27 10:56



>>22
too much work...

Name: Anonymous 2011-11-27 11:09

Awww, too hard for the little baby...

timespec start, end;
double seconds;
clock_gettime(CLOCK_CLOCK_THREAD_CPUTIME_ID, &start);
// do shit
clock_gettime(CLOCK_CLOCK_THREAD_CPUTIME_ID, &end);
seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.0;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List