# Bug in Process.times?

**URL:** <https://www.ruby-forum.com/t/bug-in-process-times/97279>\
**Category:** Ruby\
**Created:** [July 6, 2006, 2:00am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279 "2006-07-06T02:00:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/u/Robert_Joseph_Sheeh)\
**Post date:** [July 6, 2006, 2:00am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279/1 "2006-07-06T02:00:07Z")

</div>

After repeatedly getting user+system times that are longer than real  
time by a constant factor (on a single, non hyper-threading processor),  
I thought I would inspect the code for Process.times at [ruby-doc.org](http://ruby-doc.org).

It shows:  
#ifndef HZ

# ifdef CLK\_TCK

# define HZ CLK\_TCK

# else

# define HZ 60

# endif

#endif /\* HZ \*/

Unfortunately on several versions of Linux I have tried, including the  
latest Fedora and Ubuntu, this seems to give a HZ value of 60 rather  
than the correct 100, from “getconf CLK\_TCK”. (I haven’t looked any  
further into the Ruby source to examine other places the constants may  
be set.)

If I correct for this, my benchmark times now make complete sense with  
real time closely approximating user+system times on a lightly loaded  
system.

Is this a bug or have I overlooked something?

---

<div class="post-metadata">

**Author:** ![Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/u/Robert_Joseph_Sheeh)\
**Post date:** [July 6, 2006, 4:48am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279/2 "2006-07-06T04:48:14Z")

</div>

Hi,

At Thu, 6 Jul 2006 08:59:02 +0900,  
Robert Joseph Sheehan wrote in [ruby-talk:200293]:

> Is this a bug or have I overlooked something?  
> Seems a bug.

# Index: configure.in

RCS file: /cvs/ruby/src/ruby/configure.in,v  
retrieving revision 1.304  
diff -p -u -2 -r1.304 configure.in  
— configure.in 1 Jul 2006 16:40:13 -0000 1.304  
+++ configure.in 6 Jul 2006 02:26:37 -0000  
@@ -511,5 +511,5 @@ AC\_CHECK\_FUNCS(fmod killpg wait4 waitpid  
setrgid setegid setregid setresgid issetugid pause lchown  
lchmod  
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\

- 

```
    getpriority getrlimit setrlimit\

```

- 

```
    getpriority getrlimit setrlimit sysconf\
    dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\
    setsid telldir seekdir fchmod mktime timegm cosh sinh tanh log2\

```

@@ -729,4 +729,20 @@ if test $rb\_cv\_huge\_st\_ino = yes; then  
fi

+if test “$ac\_cv\_func\_sysconf” = yes; then

- AC\_DEFUN(RUBY\_CHECK\_SYSCONF, [dnl
- AC\_CACHE\_CHECK([whether _SC_$1 is supported],  
rb\_cv\_have\_sc\_[]m4\_tolower($1),
- [AC\_TRY\_COMPILE([#include \<unistd.h\>
- 

```
 ],

```

- 

```
 [_SC_$1 >= 0],

```

- 

```
 rb_cv_have_sc_[]m4_tolower($1)=yes,

```

- 

```
 rb_cv_have_sc_[]m4_tolower($1)=no)

```

- ])
- if test “$rb\_cv\_have\_sc\_[]m4\_tolower($1)” = yes; then
- AC\_DEFINE(HAVE\_\_SC\_$1)
- fi
- ])
- RUBY\_CHECK\_SYSCONF(CLK\_TCK)  
+fi
- 

# case “$target\_cpu” in m68\*|i?86|ia64|sparc\*|alpha\*) rb\_cv\_stack\_grow\_dir=-1;; Index: process.c

RCS file: /cvs/ruby/src/ruby/process.c,v  
retrieving revision 1.145  
diff -p -u -2 -r1.145 process.c  
— process.c 15 Jun 2006 06:43:17 -0000 1.145  
+++ process.c 6 Jul 2006 02:33:23 -0000  
@@ -3517,4 +3517,8 @@ rb\_proc\_times(VALUE obj)  
{  
#if defined(HAVE\_TIMES) && !defined( **CHECKER** )

- const double hz =  
+#ifdef HAVE\_\_SC\_CLK\_TCK
- (double)sysconf(\_SC\_CLK\_TCK);  
+#else  
#ifndef HZ

# ifdef CLK\_TCK

@@ -3524,4 +3528,6 @@ rb\_proc\_times(VALUE obj)

# endif

#endif /\* HZ \*/

- HZ;  
+#endif  
struct tms buf;  
volatile VALUE utime, stime, cutime, sctime;  
@@ -3529,8 +3535,8 @@ rb\_proc\_times(VALUE obj)  
times(&buf);  
return rb\_struct\_new(S\_Tms,

- 

```
  	 utime = rb_float_new((double)buf.tms_utime / HZ),

```

- 

```
  	 stime = rb_float_new((double)buf.tms_stime / HZ),

```

- 

```
  	 cutime = rb_float_new((double)buf.tms_cutime / HZ),

```

- 

```
  	 sctime = rb_float_new((double)buf.tms_cstime / HZ));

```

- 

```
  	 utime = rb_float_new(buf.tms_utime / hz),

```

- 

```
  	 stime = rb_float_new(buf.tms_stime / hz),

```

- 

```
  	 cutime = rb_float_new(buf.tms_cutime / hz),

```

- 

```
  	 sctime = rb_float_new(buf.tms_cstime / hz));

```

#else  
rb\_notimplement();

---

<div class="post-metadata">

**Author:** ![Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/u/Robert_Joseph_Sheeh)\
**Post date:** [July 6, 2006, 5:18am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279/3 "2006-07-06T05:18:45Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > 
> 
> Index: configure.in
> 
> - 
> 
> ```
> getpriority getrlimit setrlimit sysconf\
> 
> ```
> 
> - 
> 
> ```
> [_SC_$1 >= 0],
> 
> ```
> 
> case “$target\_cpu” in  
> #if defined(HAVE\_TIMES) && !defined( **CHECKER** )  
> +#endif
> 
> - 
> 
> ```
> stime = rb_float_new(buf.tms_stime / hz),
> 
> ```
> 
> - 
> 
> ```
> cutime = rb_float_new(buf.tms_cutime / hz),
> 
> ```
> 
> - 
> 
> ```
> sctime = rb_float_new(buf.tms_cstime / hz));
> 
> ```
> 
> #else  
> rb\_notimplement();

Shouldn’t we try sysconf(CLOCKS\_PER\_SEC) if \_SC\_CLK\_TCK isn’t defined  
first?

- Dan

---

<div class="post-metadata">

**Author:** ![Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/u/Robert_Joseph_Sheeh)\
**Post date:** [July 6, 2006, 9:54am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279/4 "2006-07-06T09:54:21Z")

</div>

Hi,

At Thu, 6 Jul 2006 12:17:30 +0900,  
Daniel B. wrote in [ruby-talk:200298]:

> Shouldn’t we try sysconf(CLOCKS\_PER\_SEC) if \_SC\_CLK\_TCK isn’t defined first?

Shouldn’t. CLOCKS\_PER\_SEC isn’t concerned with CLK\_TCK, and  
you can’t use it as the argument to sysconf().

---

<div class="post-metadata">

**Author:** ![Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@Robert\_Joseph\_Sheeh](https://www.ruby-forum.com/u/Robert_Joseph_Sheeh)\
**Post date:** [July 6, 2006, 10:39am UTC](https://www.ruby-forum.com/t/bug-in-process-times/97279/5 "2006-07-06T10:39:48Z")

</div>

Hi,

In message “Re: bug in Process.times?”  
on Thu, 6 Jul 2006 11:46:15 +0900, removed\_email\_address@domain.invalid writes:

|\> Is this a bug or have I overlooked something?  
|  
|Seems a bug.

Can you commit the patch?

```
						matz.
```
