From: "akr (Akira Tanaka)" Date: 2013-08-24T09:23:25+09:00 Subject: [ruby-core:56792] [ruby-trunk - Feature #8809] Process.clock_getres Issue #8809 has been updated by akr (Akira Tanaka). david_macmahon (David MacMahon) wrote: > I know it's not SI, but I often use ASCII "u" for Greek m ("��"), so :microsecond would be aliased by :us. It may be possible. I found ISO 2955. ISO 2955: Information processing - Representation units in Systems with limited Character sets > > I feel :float_s is bit curious. > > How about separating the type and the resolution into two different parameters? > > Process.clock_getres(Process::CLOCK_MONOTONIC, :float, :second) > > ...or... > > Process.clock_getres(Process::CLOCK_MONOTONIC, Float, :second) I think most useful combinations are follows. * float second * integer nanosecond (clock_gettime/clock_getres native format) The current design makes us possible to specify former as no unit argument and later as :nanosecond. Your design force us longer description for integer nanosecond. ---------------------------------------- Feature #8809: Process.clock_getres https://bugs.ruby-lang.org/issues/8809#change-41334 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/