From: "akr (Akira Tanaka)" Date: 2013-08-22T23:33:39+09:00 Subject: [ruby-core:56780] [ruby-trunk - Feature #8809][Open] Process.clock_getres Issue #8809 has been reported by akr (Akira Tanaka). ---------------------------------------- Feature #8809: Process.clock_getres https://bugs.ruby-lang.org/issues/8809 Author: akr (Akira Tanaka) Status: Open Priority: Normal Assignee: Category: Target version: How about Process.clock_getres method? POSIX defines clock_getres function to provide resolution information of clocks. I made a pacth to invoke clock_getres function. Process.clock_getres(Process::CLOCK_MONOTONIC) #=> 1.0e-09 Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE) #=> 0.00400025 The result means that the resolution of CLOCK_MONOTONIC is 1ns and the resolution of CLOCK_MONOTONIC_COARSE is 4.00025ms. Process.clock_getres has optional unit argument as Process.clock_gettime. Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond) #=> 1 Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE, :nanosecond) #=> 4000250 It supports emulated clocks as well. Process.clock_getres(:SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME) #=> 1.0000000000000002e-06 Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) #=> 1.0000000000000002e-06 The unit argument can be :hertz, which means the reciprocal of the second. Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) #=> 1000000.0 Note that Process.clock_getres(:POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is the clock ticks per second (CLK_TCK) and Process.clock_getres(:ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is CLOCK_PER_SEC. I wanted to access them easily to investigate emulated clock behaviors on various OSes. Any comments? -- http://bugs.ruby-lang.org/