From: Tanaka Akira Date: 2013-07-27T08:48:14+09:00 Subject: [ruby-core:56209] Re: [ruby-trunk - Feature #8658] Process.clock_gettime 2013/7/26 Tanaka Akira : > 2013/7/26 KOSAKI Motohiro : > >> Really? I don't think so because CLOCK_*_CPUTIME_ID have less precious than >> CLOCK_REALTIME. following "t" often show 0 on several OSs. >> >> >> t0 = clock_gettime(CLOCK_THREAD_CPUTIME_ID) >> # blah blah blah >> t1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID) >> t = t1 - t0 > > At least, my system can return 1ns unit. > (It doesn't mean 1ns accuracy, of course.) > > In following result, 4666 and 4667 are returned. > > % ./ruby -ve ' > t1 = Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :nanoseconds) > while true > t2 = Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :nanoseconds) > p t2-t1 > t1 = t2 > end > '|head -20|sort -n CLOCK_THREAD_CPUTIME_ID can return 1ns unit too. % ./ruby -ve ' t1 = Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :nanoseconds) while true t2 = Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :nanoseconds) p t2-t1 t1 = t2 end '|head -20|sort -n ruby 2.1.0dev (2013-07-19 trunk 42049) [x86_64-linux] 2091 3913 3936 3939 3975 3976 3978 4281 4466 4473 4516 4563 4666 4706 -e:5:in `p'5604 6196 6342 13047 19388 : Broken pipe (Errno::EPIPE) from -e:5:in `
' (3975 and 3976 is returned.) CLOCK_THREAD_CPUTIME_ID may be preferable than CLOCK_PROCESS_CPUTIME_ID for measuring Bignum speed because it is purely single thread. -- Tanaka Akira