Forum: Ruby Ruby Profiler and ruby-prof Issues break working code?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6d5602ac22cc57505c0d3a24b3d63108?d=identicon&s=25 Tyler Prete (Guest)
on 2006-12-31 11:30
(Received via mailing list)
I wrote some Ruby code to solve a little puzzle (
http://projecteuler.net/index.php?section=problems&id=14) that functions
correctly.  It solves for the answer and gets it right, it's just a
little
slower than I would like.  So I thought I would bring out the old
profiler
and see what I could do to speed things up.  Well... on the exact same
code
file, no changes besides 'require "profile"' it now gives me this error:

c:/ruby/lib/ruby/1.8/profiler.rb:13:in `hash': can't convert Hash into
Integer (TypeError)
    from c:/ruby/lib/ruby/1.8/profiler.rb:13:in `[]'
    from c:/ruby/lib/ruby/1.8/profiler.rb:13
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:55:in `initialize'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:55:in `initialize'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:122:in `new'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:122:in `find'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:120:in `each'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:120:in `find'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:137

It seems like it is related to the my initialize method, but it is
simple
and correct:
def initialize(num)
        @latest = num
        @sequence = [@latest]
end

So I decided to abandon the standard profiler and try RubyProf instead.
Using #require 'unprof', it also keels over:

c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:33: warning:
ruby-prof: An error occured when leaving the method Kernel#require.
   Perhaps an exception occured in the code being profiled?

And using require 'ruby-prof' and putting RubyProf.start and
RubyProf.stoparound the code I would like to profile results in:

C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:122:in `initialize': undefined method `%' for
#<Hash:0x2b8b9cc> (NoMethodError)
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:122:in `new'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:122:in `find'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:120:in `each'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:120:in `find'
    from C:/Documents and Settings/Tyler Prete/Desktop/Project
Euler/Problem14.rb:137

I truly have no idea what is going on here.  I've checked time and time
again, and this code works correctly without the profilers.  I've ran it
with ruby -c -w, and it results in no warnings and the code is valid.
Is
the profiler trying to do something  unusual here that I should be aware
of?

Thanks for any help, it is much appreciated.
--Tyler Prete
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-12-31 19:07
(Received via mailing list)
Hi,

In message "Re: Ruby Profiler and ruby-prof Issues break working code?"
    on Sun, 31 Dec 2006 19:28:39 +0900, "Tyler Prete"
<psyonic@gmail.com> writes:

|I wrote some Ruby code to solve a little puzzle (
|http://projecteuler.net/index.php?section=problems&id=14) that functions
|correctly.  It solves for the answer and gets it right, it's just a little
|slower than I would like.  So I thought I would bring out the old profiler
|and see what I could do to speed things up.  Well... on the exact same code
|file, no changes besides 'require "profile"' it now gives me this error:

<snip>

This is very weird error.  I have never seen something like this.  It
is very difficult to help you without error reproducing code.  Is it
possible for us to see your puzzle solving code that cause the
problem?  We will very appreciate if you supply information for your
platform and the version of Ruby you've run.

							matz.
6d5602ac22cc57505c0d3a24b3d63108?d=identicon&s=25 Tyler Prete (Guest)
on 2007-01-01 00:22
(Received via mailing list)
matz,

Thank you for the quick response.  I don't know which part of the code
the
problem is in, but I'm more than happy to let you look at the source
code.
It's a little too long to post it all here, but here's a link to it on
my
website.

<a href="http://www.tylerprete.com/ruby/Problem14.rb">Probl...

I'm running ruby 1.8.5 (2006-08-25) on Windows XP SP2.
Thanks for your help,
Tyler Prete
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2007-01-01 06:10
(Received via mailing list)
Hi,

In message "Re: Ruby Profiler and ruby-prof Issues break working code?"
    on Mon, 1 Jan 2007 08:21:01 +0900, "Tyler Prete" <psyonic@gmail.com>
writes:

|Thank you for the quick response.  I don't know which part of the code the
|problem is in, but I'm more than happy to let you look at the source code.
|It's a little too long to post it all here, but here's a link to it on my
|website.

You have redefined Chain.hash which is used internally in Hash to get
hash value, and should return integer value.

							matz.
6d5602ac22cc57505c0d3a24b3d63108?d=identicon&s=25 Tyler Prete (Guest)
on 2007-01-01 22:52
(Received via mailing list)
On 12/31/06, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
>
> Hi,
>
>
> You have redefined Chain.hash which is used internally in Hash to get
> hash value, and should return integer value.
>
>                                                         matz.
>
>

That solved it.

Thanks matz,
Tyler Prete
This topic is locked and can not be replied to.