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.
Tyler P. (Guest)
on 2006-12-31 12: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 P./Desktop/Project
Euler/Problem14.rb:55:in `initialize'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:55:in `initialize'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:122:in `new'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:122:in `find'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:120:in `each'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:120:in `find'
    from C:/Documents and Settings/Tyler P./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 P./Desktop/Project
Euler/Problem14.rb:122:in `initialize': undefined method `%' for
#<Hash:0x2b8b9cc> (NoMethodError)
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:122:in `new'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:122:in `find'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:120:in `each'
    from C:/Documents and Settings/Tyler P./Desktop/Project
Euler/Problem14.rb:120:in `find'
    from C:/Documents and Settings/Tyler P./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 P.
Yukihiro M. (Guest)
on 2006-12-31 20: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 P."
<removed_email_address@domain.invalid> 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.
Tyler P. (Guest)
on 2007-01-01 01: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 P.
Yukihiro M. (Guest)
on 2007-01-01 07: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 P." 
<removed_email_address@domain.invalid>
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.
Tyler P. (Guest)
on 2007-01-01 23:52
(Received via mailing list)
On 12/31/06, Yukihiro M. <removed_email_address@domain.invalid> 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 P.
This topic is locked and can not be replied to.