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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 9 Mar 2005 18:35:08 -0800 Organization: http://groups.google.com Message-ID: <1110422108.925127.54110@o13g2000cwo.googlegroups.com> References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <1110396477.596174.285520@o13g2000cwo.googlegroups.com> <112vb2t8eonuhed@corp.supernews.com> NNTP-Posting-Host: 69.170.70.49 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1110422113 16382 127.0.0.1 (10 Mar 2005 02:35:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 10 Mar 2005 02:35:13 +0000 (UTC) In-Reply-To: <112vb2t8eonuhed@corp.supernews.com> User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=69.170.70.49; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:8993 comp.realtime:1169 comp.software-eng:4730 Date: 2005-03-09T18:35:08-08:00 List-Id: CTips wrote: > jimmaureenrogers@worldnet.att.net wrote: > > > CTips wrote: > > > >>Jim Rogers wrote: > > The advantage of the built-in features are that they are a very > > good implementation of a tasking model. You seem to have two > > standards. C is good because you can do what you want while > > Ada is bad because it does not do everything for you. > > Nope, I'm not saying that. What I am saying is that: > - the safety features of Ada can come with a significant run-time cost > - you're going to end up escaping out of Ada for a lot of things > (particularily in systems programming). I am not sure exctly what you mean by escaping out of a language. This reminds me of escaping from the vi editor to run another program. Ada is quite capable of doing bit manipulations without resorting to C or Assembly. On the other hand, most operating system libraries are currently written in C, so you might want to call them from an Ada program. This is no worse than calling them from C++. My little program described earlier does not break out into other languages, and it appears to have beaten a number of C programmers who were using this exercise to explore optimizations. -- Highest bit set with Ada.Text_Io; with Ada.Calendar; use Ada.Calendar; procedure Highest_Bit_Set is Num : Integer; type Index_Type is mod 32; type Bit_Array is array(Index_Type) of Boolean; pragma Pack(Bit_Array); Overlay : Bit_Array; for Overlay'Address use Num'Address; Start, Stop : Time; begin Start := Clock; Num := 0; for X in 1..100_000 loop for I in reverse Overlay'range loop if Overlay(I) then Ada.Text_Io.Put_Line("Highest bit set is bit" & Index_Type'Image(I)); exit; end if; end loop; end loop; Stop := Clock; Ada.Text_IO.Put_Line("Execution time: " & Duration'Image(Stop - Start)); end Highest_Bit_Set; On my AMD 64 pc running Win XP this program ran, with 100,000 iterations in 0.02 seconds. This calculates to an average time per iteration of 0.0000002 seconds. My choice of calculating for a value of 0 gives worst case performance, and does not slow the program to do I/O. This combination gives what I think is a fair measure of the performance of the program. I did not disable any Ada run-time checking. I believe the compiler took care of those issues automatically. > > C doesn't have that cost. However, if you want to have similar levels of > checking, you have to roll your own run-time checks. On the other hand, > because you're rolling your own, the run-time checks are a lot less > expensive. > I am not sure I agree that this is always true. If it were, then I would not trust any of the code generated by a compiler to be efficient. My experience is that a good compiler in almost any language produces more efficient object code than most humans can produce. If this were not so, then we should all be using only Assembly. > Also, since a lot of interesting things require escaping from the core > language and bending the rules of the language, you have two options: > - you can write it all in assembly > - or you can write in a language where you can reasonably expect that > your bending of the rules won't make the compiler do something you > didn't expect. What sort of things will the compiler do that I do not expect? I assume you have an example in mind, but right now I cannot think of one. Jim Rogers