From: Robert Feldt Date: 2000-09-04T23:13:30+09:00 Subject: [ruby-talk:4781] Bug in Time.times on NT? Hi, There seems to be a bug in the script below when I run it on my machine. (If this has been fixed in 1.6 then please discard this mail). The problem might be with the 'time_s_times' func in time.c: hProc = GetCurrentProcess(); GetProcessTimes(hProc,&create, &exit, &kernel, &user); return rb_struct_new(S_Tms, rb_float_new((double)(kernel.dwHighDateTime*2e32+kernel.dwLowDateTime)/2e6 ), rb_float_new((double)(user.dwHighDateTime*2e32+user.dwLowDateTime)/2e6), rb_float_new((double)0), rb_float_new((double)0)); where I think the conversion should be something like rb_float_new((user.dwHighDateTime * CONST_2_to_32 + user.dwLowDateTime) / 1e7) etc... where CONST_2_to_32 is 2**32 ie. 4294967296.0 If I've correctly unerstood the FILETIME structure returned from Win32 API GetProcessTimes (with two 32-bit values giving the number of 100 nanosec intervals). Regards, Robert The script: #!/usr/local/bin/ruby # # When run on my IBM Thinkpad with Nt4, cygwin 1.1 & Ruby 1.4.5 this script # results in: # # bash-2.04$ time ruby ruby_times_test.rb # Time: real = 9.5 s, user = 157.5 s, system = 0.2 s # # real 0m9.584s # user 0m9.483s # sys 0m0.060s # # How come user CPU time is reported to be 157.5 secs even though total # time was only about 10 secs? Bug? Fixed in 1.6? # s = 0 t_start = Time.now pt_start = Time.times 1e6.to_i.times{ |i| s+= i } pt_end = Time.times t_end = Time.now print "Time: real = %.1f s, user = %.1f s, system = %.1f s\n" % [t_end - t_start, pt_end.utime - pt_start.utime, pt_end.stime - pt_start.stime]