Thanks to all who helped me understand Ruby’s treatment of
multidimensional
arrays. I was able to successfully finish the 8-puzzle program
yesterday
afternoon. I’m been putting some code in to measure the time it takes
to
run the program this morning. Since this is my first “big” program in
Ruby,
I am too embarrassed to distribute copies as I am sure there are better
ways
to write the code.
Ruby, as you all know, is not as fast as compiled code, like C++ or
such.
It takes about 15 minutes for my program to execute. Most of that time
appears to come from the searching for matches in the two queues, a
Priority
Queue, for nodes that may or may not be part of the path to the goal,
and a
regular queue (not the Queue of the Thread class). I ran an insolvable
starting/goal combination all last night and this morning there were
1301+
entries in the Closed queue and 731+ entries in the Open queue and
nowhere
near a termination. (It would terminate if all combinations of the 3x3
grid
{9 factorial combinations} were examined and the Open queue had been
reduced
to zero entries.) If I have time I’ll return to the code and see if I
can
rewrite it to execute faster.
Anyway, as I was putting the one line of code to display the time, I
realized that it was the system clock time that was being displayed. I
would like to also display the cpu time. Is it possible to display the
CPU
time? By that, I mean the amount of CPU time consumed between a
starting
and ending point in the code. As anyone who has used procexp.exe on a
Windows environment knows, the CPU time must be less than the Clock
time, as
other asynchronous are getting their slice of the time pie, although I
see
Ruby running at 50% to 95% of the CPU time. The code to record CPU time
will probably unique for a given OS, if it exists. I run on Windows XP
with
Ruby 1.8. Any ideas how this could be done? It is not documented in
any of
the books I have.
No Sam