On Apr 18, 2011, at 11:30 , Martin Hansen wrote:

> WJ wrote in post #993576:
>> Martin Hansen wrote:
>>=20
>>> The below code is too slow for practical use. I need it to run at =
least
>>> 20 times faster. Perhaps that is possible with some C code? I have =
no
>>> experience with writing Ruby extensions. What are the pitfalls? =
Which
>>> part of the code should be ported? Any pointers to get me started?
>>=20
>> Please give a clear description of the algorithm, and then
>> give some sample input and output.
>=20
>=20
> Here is a working version of the code that can be profiled (though it=20=

> will take forever with 20M iterations):
>=20
> http://pastie.org/1808127
>=20
> The slow part according to profiler is:

Profiling is great, but you also need to write a benchmark in order to =
objectively measure the work you're doing. You might also want to write =
microbenchmarks against the bottlenecks you identify in your profiling =
work. Eg:

>  def match?(char1, char2)
>    (EQUAL[char1.upcase.ord] & EQUAL[char2.upcase.ord]) !=3D 0
>  end

That would be really easy to write tests and a benchmark against and =
then rewrite in C using RubyInline... without tests and a benchmark tho, =
you won't know that you've done it correctly and provides a measurable =
benefit.