M
M. Edward (Ed) Borasky
A while back, I wondered if anyone had ever profiled the Ruby
interpreter itself with "gprof". I don't recall if anyone ever answered,
so I ran a short test to see what would happen. I'll spare you the
details, since I put everything up on my CVS repository on RubyForge.
http://rubyforge.org/cgi-bin/viewvc.cgi/MatrixBenchmark/?root=cougar
The benchmark code itself is "MatrixBenchmark.rb" ... this is where my
desire for "m[i, j] = -1" came from. I ran this using stock Ruby
1.8.4 source recompiled with the "-g -pg" options and did the standard
"gprof" call graph, plus an annotated source. The call graph/profile is
"profile.txt" and the annotated *Ruby* source is "source.txt". That last
one is a bit large, so don't download it unless you're intensely curious.
This is the sort of code I'd *like* to write in pure Ruby, rather than
having to call a C library for efficiency. The matrix I generated is
quite ill-conditioned. It's quite possible that a "standard" floating
point numerical determinant or matrix inversion routine would choke on
it, while the combination of "matrix", "mathn" and "rational" I used had
no problem with it. In short, I'm willing to pay for rational arithmetic
and correct results, but not for an inefficient interpreter. So if
someone is going to rewrite Matrix in C, they need to do the underlying
arithmetic too.
If I get a chance, I'm going to try this out with YARV (assuming YARV
will run it). Also, bear in mind that the "-g" compile turns off all
optimization and the profiling introduces some overhead itself. A
regular Ruby interpreter would run the actual benchmark faster.
interpreter itself with "gprof". I don't recall if anyone ever answered,
so I ran a short test to see what would happen. I'll spare you the
details, since I put everything up on my CVS repository on RubyForge.
http://rubyforge.org/cgi-bin/viewvc.cgi/MatrixBenchmark/?root=cougar
The benchmark code itself is "MatrixBenchmark.rb" ... this is where my
desire for "m[i, j] = -1" came from. I ran this using stock Ruby
1.8.4 source recompiled with the "-g -pg" options and did the standard
"gprof" call graph, plus an annotated source. The call graph/profile is
"profile.txt" and the annotated *Ruby* source is "source.txt". That last
one is a bit large, so don't download it unless you're intensely curious.
This is the sort of code I'd *like* to write in pure Ruby, rather than
having to call a C library for efficiency. The matrix I generated is
quite ill-conditioned. It's quite possible that a "standard" floating
point numerical determinant or matrix inversion routine would choke on
it, while the combination of "matrix", "mathn" and "rational" I used had
no problem with it. In short, I'm willing to pay for rational arithmetic
and correct results, but not for an inefficient interpreter. So if
someone is going to rewrite Matrix in C, they need to do the underlying
arithmetic too.
If I get a chance, I'm going to try this out with YARV (assuming YARV
will run it). Also, bear in mind that the "-g" compile turns off all
optimization and the profiling introduces some overhead itself. A
regular Ruby interpreter would run the actual benchmark faster.