Subject: Reply to Chen regarding Porting the Black Hole Solver to C

From: Shlomi Fish <[email-masked]>
Date: Wed, 25 Aug 2010 13:10:24 +0300

Hi all,

on Twitter I mentioned that I've started porting my Black Hole Solitaire 
solver from Perl to C and that it will hopefully make it faster:

http://twitter.com/shlomif/status/22027561541

Chen replied thusly:

http://twitter.com/gwenshap/status/22031112275

{{{
Why go to all the effort without knowing what causes your code to be slow and 
how C can help? Don't guess when you can measure!
}}}

So here is my reply: my code is not slow as Perl code goes, but it still often 
takes many seconds to solve a given deal of Black Hole Solitaire. As I'd like 
to run the solver on a range of deals in order to collect some statistics, I 
expect the Perl code to be too slow for that. The code is algorithmic and I'd 
expect that executing the bytecode by the Perl 5 backend to incur a large 
amount of overhead.

My code is very minimal as it is, and it's not very complicated or 
sophisticated so I expect a conversion to C to yield great speed (and possibly 
also memory consumption) benefits.

For more information see my:

* http://en.wikibooks.org/wiki/Optimizing_Code_for_Speed

I've replied to it here instead of on Twitter, because I didn't have enough 
character quota to express myself properly. (Also I thought it may be of 
interest to the list.).

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

---

From: Gwen Shapira <[email-masked]>
Date: Thu, 26 Aug 2010 11:40:37 -0700

> expect that executing the bytecode by the Perl 5 backend to incur a large

So your code is CPU bound and you are counting on the C optimizer to
reduce the CPU usage?

The reason I'm drilling down into the details is that I've been
interested in the question of "In what conditions can a program be
made faster by switching to a different language?" and you seem to
have a perfect test case :)

In my world code is usually made faster by making it do less physical
IO or less logical IO (aka use less memory) or by resolving
concurrency issues. All those problems are rarely solved by switching
to a different language - although some folks seem to solve
concurrency problems by using Erlang.

I'm curious how it works in other areas that I'm less familiar with.
Could you post benchmarks? Do you have profiler output for your
program (i.e. where time is spent before and after)?

Chen