Execution Speed (compare to C++)

It is not completely trivial to compare the execution speed of different programming languages, because some problems may suit one language better than another. Nevertheless such comparison is interesting.

This article describes a little simple comparison of Visual Prolog and Microsoft C++. The comparison does not claim any scientific accuracy; it is just supposed to give an indication.

The classical Towers of Hanoi problem is used for the test, the actual writing of the result to the standard output stream is skipped, because otherwise the test take nearly the same time because all the time is spend in drawing and scrolling the console window.

The test is carried out with Visual Prolog 7.2 and Microsoft C++ (Visual Studio 2005).

Visual Prolog run
class main predicates run : core::runnable. end class main

implement main

clauses run:- console::init, profileTime::init, profileTime::start_pr("hanoi"), hanoi(25, "a", "b", "c"), profileTime::stop_pr("hanoi"), profileTime::printAndReset(stdio::getOutputStream).

class predicates hanoi : (positive N, string SourcePole, string AuxPole, string TargetPole). clauses hanoi(0, _SourcePole, _AuxPole, _TargetPole) :- !.   hanoi(N, SourcePole, AuxPole, TargetPole) :- hanoi(N-1, SourcePole, TargetPole, AuxPole), /* stdio::writef("Move from % to %\n", SourePole, TargetPole),*/ hanoi(N-1, AuxPole, SourcePole, TargetPole).

end implement main

goal mainExe::run(main::run).

The result was this

Steps = 134217727

+---+---++++---+ +---+---++++---+
 * Predicate       | Calls |   AvgNet   |   Netto    |   Average  |    Total  |
 * hanoi            |     1 |  5.6989841 |   5.698984 |   5.698984 |   5.698984|

C++ run
In Debug mode this program produced:

Steps = 134217727

Program takes 38.45 seconds.

In Release mode it produced:

Steps = 134217727

Program takes 1.95 seconds.

Summary
So the Release version of the C++ program is around 3 times faster than the Visual Prolog program which is 6.75 times faster than the Debug version of the C++ program.

So this Visual Prolog program though significantly slower than the optimized C++ program is however closer to the optimized C++ program than to the un-optimized C++ program.