From: Kristof Bastiaensen Date: 2006-08-09T00:00:06+09:00 Subject: Re: For performance, write it in C - Part 3, Source code now available On Tue, 08 Aug 2006 10:54:53 +0100, Jon Harrop wrote: > Peter Hickman wrote: >> Isaac Gouy wrote: >> > D and Clean are other languages you might look at, but using a >> > different language won't make what you're trying to do any more >> > feasible. >> >> True, > > Even for such a simple task, the ability to use sophisticated data > structures, higher-order functions and other constructs can make a solution > practically feasible in some languages and infeasible in others. > > Simulated annealing solution to the travelling salesman problem is another > seemingly simple task that benefits enormously from high-level constructs. > The naive Fortran code given in Numerical Recipies (the de-facto standard > monologue) has an O(n) bottleneck that can be trivially reduced to O(sqrt > N) using closures or O(ln n) using balanced trees, neither of which are > feasible in C/Fortran for most science students. > >> but as I've said before C is a fragile language to work in if >> you've come from a scripting background. A program will compile and then >> crash with not the slightest hint at what went wrong, so any language >> that will allow me to get that sort of performance with a better support >> is a good thing. I will be learning Ocaml for this reason alone. > > Absolutely, C is a systems programming language. People are abusing it when > they advocate it for tasks like this. C++ is slightly better but, as I've > shown, you've lost the performance advantage that you thought you had once > you start using its features. OCaml's great. It's succinct, safe and fast. > The main downside is probably that you have to get to grips with its type > system. > > Here are my benchmarks for the final versions: > > 0.368s gcc -O2 > 0.458s ocamlopt -inline 100 -unsafe > 0.605s g++ -O2 > 0.644s java > > I can't seem to run the Perl or Ruby out of the box: how do I get the extra > packages that I need? For my and Simon Kroegers version you need the permutation.rb file, which you can install with rubygems, or extract it from the sourcepackage at http://permutation.rubyforge.org/ (which I did). Perhaps it would be better to include the permutation.rb file on the webpage? Kristof