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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: "Clifford J. Nelson" Subject: Re: Ada95 speed Date: 1999/05/18 Message-ID: <3740FE0A.D198003@gte.net>#1/1 X-Deja-AN: 479300184 Distribution: world Content-Transfer-Encoding: 7bit References: <3740C535.7C6200A8@gte.net> <3740C7B1.4CD68529@aasaa.ofe.org> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" X-Abuse-Info: Otherwise we will be unable to process your complaint properly X-Complaints-To: abuse@gte.net X-Trace: 9mr0rYoRUiXQpt8VPlsCP+dcYu4GvGHpN8Md6zclzY1LMxBrDQvjEfySrBz8o084lECdsxBOvlNL!raDKgKchl4TCimZ9Um7wR25dqTQ9yEoxDaMaXp5COQv56bpS9SufBg== MIME-Version: 1.0 NNTP-Posting-Date: Tue, 18 May 1999 04:49:50 GMT Reply-To: cnelson9@gte.net Newsgroups: comp.lang.ada Date: 1999-05-18T00:00:00+00:00 List-Id: David Starner wrote: > "Clifford J. Nelson" 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. > > Was the code identical? I've had two Mandelbrot generators on the same > system, and one took hours and one took seconds to do the Mandelbrot. > Since the later was carefully and extensively tuned (cf. Fractint), I > get the impression that the comparision code may have been similarily > tuned. Maybe not, but I think it showed 256 colors not just 64 like mine. > > > > exit when (abs( Z)) > 2.0; > > This line is probably the problem. The C code probably never did a sqrt; > most likely, the code looked like (z.i* z.i + z.r * z.r) > 4.0. Do the > same thing in Ada, and you'll probably see a huge improvement. Yes! By a factor of five. Thanks. Here is the program again. It should run on any Ada system I guess. with Ada.Numerics.Complex_Types; with Calendar; with Ada.Text_io; use Ada.Numerics.Complex_Types; use Calendar; use Ada.Text_io; procedure timetest is Ch : String (1..2); procedure Display(Mag : in Float) is It : Integer; X, Y : Float; C, Z : Complex; Num_Iters : constant := 64; Vertical_Maximum : constant Short_Integer := 700; Horizontal_Maximum : constant Short_Integer := 1200; 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 Put(Duration'Image(Seconds(Clock))); Y := StartY; for Y_Pos in 0..700 loop X := StartX; for X_Pos in 0..1200 loop Z := (X, Y); -- Complex value; standard Ada 95! C := Z; for I in 0..Num_Iters loop It := I; exit when (Z.Re * Z.Re + Z.Im * Z.Im) > 4.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; Put(Duration'Image(Seconds(Clock))); end Display; begin -- Main body of program timetest Display(0.0025); -- draw the fractal! Get(Ch); end timetest;