Project

General

Profile

Actions

Bug #663

closed

Benchmark.measure outputs different result when executed using command line "ruby -e ..."

Added by greck (Artem Vorozhtsov) over 15 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
[ruby-core:19388]

Description

=begin
I've tested it on :

  • ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux]
  • ruby 1.8.5 (2006-08-25) [i386-linux]

Sorry, I've not tested it against 1.9 and 1.8.7.

[artem@dev bm_test]$ cat a.c
int main() {
int i = 0, k = 0, n = 1000000000;
for(i = 0 ; i< n; i++){ k += i*i; }
return k;
}
[artem@dev bm_test]$ make a
cc a.c -o a
[artem@dev bm_test]$ ruby -rbenchmark -e "puts Benchmark.measure{ ./a }"
0.000000 0.000000 0.000000 ( 0.000011)
[artem@dev bm_test]$ echo 'puts Benchmark.measure{ ./a }' > b.rb
[artem@dev bm_test]$ cat b.rb
puts Benchmark.measure{ ./a }
[artem@dev bm_test]$ ruby -rbenchmark b.rb
0.000000 0.000000 4.660000 ( 4.652781)

Bugs:

  1. "ruby -e" : "total" is zero
  2. "ruby -e" : "real" is too small (should be ~ 4 seconds)
  3. "ruby" : "total" is not equal to "user" + "system" in the last example.
    =end
Actions #1

Updated by mame (Yusuke Endoh) over 15 years ago

=begin
Hi,

Thank you for your report.

2008/10/19 Artem Vorozhtsov :

Bugs:

  1. "ruby -e" : "total" is zero
  2. "ruby -e" : "real" is too small (should be ~ 4 seconds)

I think ./a is executed by your shell. If so, it's not a bug of ruby.

$ ruby19 -rbenchmark -e "puts Benchmark.measure { ./a }"
0.000000 0.000000 0.000000 ( 0.000000)

$ ruby19 -rbenchmark -e 'puts Benchmark.measure { ./a }'
0.000000 0.000000 7.540000 ( 7.540114)

  1. "ruby" : "total" is not equal to "user" + "system" in the last example.

While "user" and "system" show CPU time that only the process comsumed,
"total" shows CPU time that both the process and its children consumed.
I don't know whether it is intended.

You can see the user and system CPU time that both consumed in the
following way:

$ ruby19 -rbenchmark -e 'puts Benchmark.measure { ./a
}.format("%10.6U %10.6Y %10.6t %10.6r\n")'
6.460000 0.000000 6.460000 ( 6.460097)

--
Yusuke ENDOH

=end

Actions #2

Updated by shyouhei (Shyouhei Urabe) over 15 years ago

  • Status changed from Open to Rejected

=begin

=end

Actions #3

Updated by greck (Artem Vorozhtsov) over 15 years ago

=begin
2008/10/19 Yusuke ENDOH :

Hi,

Thank you for your report.

2008/10/19 Artem Vorozhtsov :

Bugs:

  1. "ruby -e" : "total" is zero
  2. "ruby -e" : "real" is too small (should be ~ 4 seconds)

I think ./a is executed by your shell. If so, it's not a bug of ruby.

$ ruby19 -rbenchmark -e "puts Benchmark.measure { ./a }"
0.000000 0.000000 0.000000 ( 0.000000)

$ ruby19 -rbenchmark -e 'puts Benchmark.measure { ./a }'
0.000000 0.000000 7.540000 ( 7.540114)

:)

I'm really sorry.

  1. "ruby" : "total" is not equal to "user" + "system" in the last example.

While "user" and "system" show CPU time that only the process comsumed,
"total" shows CPU time that both the process and its children consumed.
I don't know whether it is intended.

You can see the user and system CPU time that both consumed in the
following way:

$ ruby19 -rbenchmark -e 'puts Benchmark.measure { ./a
}.format("%10.6U %10.6Y %10.6t %10.6r\n")'
6.460000 0.000000 6.460000 ( 6.460097)

--
Yusuke ENDOH

Thanks!

Then documentation should be fixed.
At http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/classes/Benchmark.html
one could read
"This report shows the user CPU time, system CPU time, the sum of the
user and system CPU times, and the elapsed real time. The unit of time
is seconds. "

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0