From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_MSGID, PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bcdac28207102750 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Ada95 speed Date: 1999/05/18 Message-ID: #1/1 X-Deja-AN: 479262001 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <3740C535.7C6200A8@gte.net> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1999-05-18T00:00:00+00:00 List-Id: Clifford J. Nelson (cnelson9@gte.net) wrote: : Ten years ago a Mandelbrot set computation and display on a 1200x700 : screen with eight bit color took six seconds in C on a MacIIfx. : The following computations (leaving out all the with statements that you : need for the Mac) take ten seconds on an iMac 266 MHertz Mac OS 8.5.1 : with the CodeBuilder Ada95 GNU from Tenon. I think it should run ten : times faster. : Is Ada95 slow in order to be safe? There is nothing in this code that would require any constraint checks. You could put a "pragma Suppress(all_checks);" at the top of your source file to verify this. : Is GNU Ada95 slower than most Adas? Not particularly. : Is the iMac slow? Mac OS 8.5.1 slow? CodeBuilder? The iMac is certainly much master than the MacIIfx in general, at least for pure computation. Probably the time is dominated by the drawing of the pixels. The only mildly complicated numeric operation in the code below is the call on "abs" for a complex number. That involves 2 multiplies and a square-root. It would be useful to see where the time is going. Chances are that the generated code is running much faster, and the time is all spent in the graphics routines drawing pixels. : Why does it take so long? My bet is on the graphic output routines. The code generated by the Ada compiler is probably taking an immeasurably small amount of time. Try changing the program so that it only does the computation. Then add back in the graphics output. Measure the difference in execution time... : Program follows-------- : with Ada.Numerics.Complex_Types; : use Ada.Numerics.Complex_Types; : procedure Mandel is : -- Initialize procedure goes here for windRect.bottom and windRect.top : procedure Display(Mag : in Float) is : It : Integer; : X, Y : Float; : C, Z : Complex; : Num_Iters : constant := 64; : Vertical_Maximum : constant Short_Integer := windRect.bottom; : Horizontal_Maximum : constant Short_Integer := windRect.Right; : Ver_Size : constant Float := Float(Vertical_Maximum + 1); : Hor_Size : constant Float := Float(Horizontal_Maximum + 1); : StartY : constant Float := -Mag * Ver_Size; : StartX : constant Float := -Mag * Hor_Size; : Step : constant Float := 2.0 * Mag ; : begin : Y := StartY; : for Y_Pos in windRect.top..windrect.bottom - 1 loop : X := StartX; : for X_Pos in windRect.left..windRect.right loop : Z := (X, Y); -- Complex value; standard Ada 95! : C := Z; : for I in 0..Num_Iters loop : It := I; : exit when (abs( Z)) > 2.0; : Z := Z * Z + C; -- Complex arithmetic : end loop; : -- draw pixel here in color depending on variable It. : X := X + Step; : end loop; : Y := Y + Step; : end loop; : end Display; : begin -- Main body of program Mandel : Initialize; : Display(0.0025); -- draw the fractal! : loop : exit when Events.Button; : end loop; : end Mandel; -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA