Turbo Pascal version 1.0 Byte Magazine ad and the 8-Queens benchmark

Posted by on in Blogs
In my first Turbo Pascal version 1.0 25th anniversary blog post I included a bitmap of the Byte Magazine advertisement. In the ad has a graphic showing bar chart comparisons between Turbo Pascal version 1.0 ($49.95) and Digital Research Pascal MT+ (priced, if I remember correctly, at somewhere around $500). The bar charts denote comparisons of Speed, Disk Space, and Price.

Below the graphic on the left side of the Byte ad is a table with features and benchmarks comparisons between Turbo Pascal version 1.0, JRT Pascal, and Pascal MT+. Included in the table are benchmark results comparing compilation and execution speeds between the three compilers.



I don't have all the compilers to be able to check the compilation results (the ad says that Turbo Pascal version 1.0 compiled 10-70 faster that the other two). But I can test Turbo Pascal version 1.0's execution speed on my current, Dell Precision M6300, notebook computer.

A note below the table contains the text: Benchmark data based on EightQueens in "Algorithms + Data Structures = Programs" by N. Wirth (Prentice Hall, publisher). The table lists 6 seconds for Turbo Pascal's execution speed of the algorithm (versus 69 seconds for JRT Pascal and 8 seconds for Pascal MT+).

While I don't know where the source code is for the benchmark comparisons, I do have my original copy of Nicklaus Wirth's book from 1976. The Eight Queens problem is described in the "Recursive Algorithms" chapter starting on page 143. So I set about to see what execution speed I could get on my notebook computer.

I used Turbo Pascal version 1.0 and typed in the extended Eight Queens algorithm (listed on pages 146-147) which determines all 92 solutions of the eight queens problem. I added logic to run the algorithm a specific number of times to approach the 6 second execution speed for the PC (not specified in the ad) that was used.

In the listing you'll see that I used Turbo Pascal version 1.0's MsDos runtime library procedure to get the DOS start and end times for the benchmark. To get the right register values for the DOS call, I used Ray Duncan's Advanced MSDOS Programming book (Microsoft Press), page 324, Get System Time, Int 21h function 2Ch (or 44 decimal). I also commented out the call to display the results (for benchmark timing purposes). Here is the source code:

    program eightqueens;
    {
    Eight Queens problem - recursive edition
    from Nicklaus Wirth's book:
    Applications + Data Structures = Programs }{
    Modified 11/06/2008 by David Intersimone "David I"
    to work with Turbo Pascal version 1.0:
    1 - added NumberOfIterations and loop to be able to benchmark
    on modern circa 2008 PCs
    2 - added MSDOS calls Int21h with AH=2Ch to get System Time
    3 - commented out the call to 'print' the solutions to remove
    screen output from the benchmark time
    }

    type
    MSDOS_Parameters_Type = record
    AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
    end;

    const
    NumberOfIterations = 12000; {for benchmarking on modern PCs how many times to solve it}

    var
    i: Integer;
    a: array[1..8] of boolean;
    b: array[2..16] of boolean;
    c: array[-7..7] of boolean;
    x: array[1..8] of Integer;
    SolutionIterations : Integer;
    MSDOSParameters : MSDOS_Parameters_Type;

    procedure print;
    var
    k: Integer;
    begin
    for k := 1 to 8 do Write(x[k]:4);
    Writeln;
    end;

    procedure try(i:Integer);
    var
    j: Integer;
    begin
    for j := 1 to 8 do
    if a[j] and b[i+j] and c[i-j] then
    begin
    x[i] := j;
    a[j] := false;
    b[i+j] := false;
    c[i-j] := false;
    if i < 8 then
    try(i+1)
    { else
    print };
    a[j] := true;
    b[i+j] := true;
    c[i-j] := true;
    end
    end {try};

    begin
    Writeln('Running ',NumberOfIterations,' iterations');
    Writeln;
    Write('Press ENTER to start searching for the 92 solutions...');
    Readln;
    MSDOSParameters.AX := $2C00;
    MsDos(MSDOSParameters);
    Writeln('Start Time: ',Hi(MSDOSParameters.CX),':',Lo(MSDOSParameters.CX),
    ':',Hi(MSDOSParameters.DX),'.',Lo(MSDOSParameters.DX));
    for SolutionIterations := 0 to NumberOfIterations-1 do begin
    for i := 1 to 8 do a[i] := true;
    for i := 2 to 16 do b[i] := true;
    for i := -7 to 7 do c[i] := true;
    try(1)
    end;
    MSDOSParameters.AX := $2C00;
    MsDos(MSDOSParameters);
    Writeln('End Time: ',Hi(MSDOSParameters.CX),':',Lo(MSDOSParameters.CX),
    ':',Hi(MSDOSParameters.DX),'.',Lo(MSDOSParameters.DX));
    Readln;
    end.


I compiled and ran the program both in memory from Turbo Pascal version 1.0 and I also created a .COM executable (size=9,686 bytes) and ran the program from the command line. Notice that I had to run the algorithm 12,000 times (NumberOfIterations = 12000) to get execution time approaching the 6 second mark.

  

I also created a Delphi 2009 command line executable (size = 96,256 bytes) of the same Eight Queens benchmark. I had to make a few changes to the source code above: replace MsDos call to use the Now() function, rename the 'try' procedure to 'try8queens' because 'try' is a reserved word in Delphi, and increase the number of iterations to 36,000 (NumberOfIterations = 36000) to approach the 6 second execution time reported in the original benchmark results. Here is the Delphi 2009 source code:

    program Queens_Delphi;

    {$APPTYPE CONSOLE}

    uses SysUtils;

    {
    Eight Queens problem - recursive edition
    from Nicklaus Wirth's book:
    Applications + Data Structures = Programs
    Modified 11/06/2008 by David Intersimone "David I"
    to work with Delphi 2009:
    1 - added NumberOfIterations and loop to be able to benchmark
    on modern circa 2008 PCs
    2 - used Delphi's Now() function to get the System Time
    3 - commented out the call to 'print' the solutions to remove
    screen output from the benchmark time
    4 - renamed original 'try' function to try8queens - try is a reserved word in Delphi
    }

    const
    NumberOfIterations = 36000; {for benchmarking on modern PCs how many times to solve it}

    var
    i: Integer;
    a: array[1..8] of boolean;
    b: array[2..16] of boolean;
    c: array[-7..7] of boolean;
    x: array[1..8] of Integer;
    SolutionIterations : Integer;

    procedure print;
    var
    k: Integer;
    begin
    for k := 1 to 8 do Write(x[k]:4);
    Writeln;
    end;

    procedure try8queens(i:Integer);
    var
    j: Integer;
    begin
    for j := 1 to 8 do
    if a[j] and b[i+j] and c[i-j] then
    begin
    x[i] := j;
    a[j] := false;
    b[i+j] := false;
    c[i-j] := false;
    if i < 8 then
    try8queens(i+1)
    { else
    print };
    a[j] := true;
    b[i+j] := true;
    c[i-j] := true;
    end
    end {try};

    begin
    try
    Writeln('Running ',NumberOfIterations,' iterations');
    Writeln;
    Write('Press ENTER to start searching for the 92 solutions...');
    Readln;
    Writeln('Start Time: '+FormatDateTime('hh:nn:ss.zzz',Now()));
    for SolutionIterations := 0 to NumberOfIterations-1 do begin
    for i := 1 to 8 do a[i] := true;
    for i := 2 to 16 do b[i] := true;
    for i := -7 to 7 do c[i] := true;
    try8queens(1)
    end;
    Writeln('End Time: '+FormatDateTime('hh:nn:ss.zzz',Now()));
    Readln;
    except
    on E:Exception do
    Writeln(E.Classname, ': ', E.Message);
    end;
    end.




Byte Magazine mentions the Turbo Pascal version 1.0 ad in "A Brief History of Programming Languages" list at http://www.byte.com/art/9509/sec7/art19.htm. For November 1983, the article says "Borland's Turbo Pascal hits the scene like a nuclear blast, thanks to an advertisement in BYTE magazine."

Whether you are fan or critic of benchmarks, it was fun to take some of my old books off the shelf, dust them off, and type in some old Pascal code.

[ David I. note - if you have Turbo Pascal version 1.0 stories to share, send them to This email address is being protected from spambots. You need JavaScript enabled to view it. and I will post some of them during this 25th anniversary month.]


About
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.

Comments

  • Guest
    okkie Thursday, 6 November 2008

    on my machine (Dell core 2 duo on Vista) the Delphi 2007-version takes more than 7 seconds.

    if I understand this article, in all these years of advancing Delphi and advancing processors the execution speed of this algorithm is not improved?

  • Guest
    Dennis Thursday, 6 November 2008

    @okkie:
    just read the text - 3 times faster.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: