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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: 108717,a7c8692cac750b5e X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,gid108717,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada,comp.realtime,comp.programming,comp.software-eng Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) From: Jim Rogers 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> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <1134l8n86c5f163@corp.supernews.com> Followup-To: comp.lang.ada,comp.realtime User-Agent: Xnews/5.04.25 Message-ID: <6UtYd.126861$Th1.29444@bgtnsc04-news.ops.worldnet.att.net> Date: Sat, 12 Mar 2005 04:05:22 GMT NNTP-Posting-Host: 12.73.181.193 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1110600322 12.73.181.193 (Sat, 12 Mar 2005 04:05:22 GMT) NNTP-Posting-Date: Sat, 12 Mar 2005 04:05:22 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:9197 comp.realtime:1333 comp.programming:17851 comp.software-eng:4900 Date: 2005-03-12T04:05:22+00:00 List-Id: CTips wrote in news:1134l8n86c5f163@corp.supernews.com: > Jim Rogers wrote: >> CTips wrote in >> news:11329cb96h2p19f@corp.supernews.com: >> >> >>>Since it appears that several people out here are making some very >>>basic mistakes when they report benchmark numbers, I thought I'd write >>>a small note on how to do benchmarking. >>> >> >> [snip advice] >> >>>10. Make sure that your numbers are reproducible: report >>> - your times >>> - your hardware >>> - your system >>> * OS (with version) >>> * compiler (with version) >>> - the compiler flags used >>> >>> >> >> >> Let's see if this helps. >> I have adjusted my program to meet some of your advice. >> The I/O at the end is not included in the reported timing. >> The program now runs for > 1 second. > > Close, but still has one problem. You're using Ada.Calendar.Clock, > which, IIRC, returns the actual wall-clock time. So, if you were swapped > out in the middle, you would be over-reporting the time. Isn't there > some Ada call that is the equivalent of POSIX clock() [or, better, > times()]? > > If I look at your numbers, it seems that you using 2e-7 seconds per > call. On a 2GHz AMD, that translates to 388 cycles per call. > > IIRC, the C codes that were posted to find the highest bit set thread > were about 1/10th of that number. Just to double check, I wrote and > measured some C code. On my 3GHz Xeon running with cygwin on WinXP, when > compiled with gcc3.3.3 using -mpcu=i686 -O0, I got a total run-time of > 2.3s, for about 69 cycles/iteration, and with -O2 I get 0.94s for about > 28 cycles/iteration. > > We're comparing a Xeon with a AMD so its not apples to apples, but > still, it suggests that either your timing methodology could use some > work, or that the code generated is quite bad. I have created another version and downloaded the latest cygwin to try to make the system as similar as possible. I have translated your example into Ada for another increase in similarity. compiled with -gnatwu -gnato -I Using the cygwin time command I got a total run-time of 2.1s. With -O2 I get 1.1s My speed appears to be very similar to yours. -- Highest_Bit2 -- More efficient algoritm than Highest_Bit with Interfaces; use Interfaces; with Ada.Command_Line; use Ada.Command_Line; procedure Highest_Bit2 is function Find_Highest_Bit(N : Unsigned_32) return Unsigned_32 is D : Unsigned_32 := 0; V : Unsigned_32 := N; begin if V > 16#FFFF# then D := D + 16; V := Shift_Right(Value => V, Amount =>16); end if; if V > 16#FF# then D := D + 8; V := Shift_Right(Value => V, Amount => 8); end if; if V > 16#F# then D := D + 4; V := Shift_Right(Value => V, Amount => 4); end if; if V > 3 then D := D + 2; V := Shift_Right(Value => V, Amount => 2); end if; if V > 1 then D := D + 1; V := Shift_Right(Value => V, Amount => 1); end if; if V > 0 then D := D + 1; end if; return D; end Find_Highest_Bit; type Index is mod 32; type Val_Array is array(Index) of Unsigned_32; Val : Val_Array; S : Unsigned_32 := 0; I : Index := 0; U : Unsigned_32 := 1; begin loop Val(I) := Shift_Left(Value => U, Amount => Natural(I)) - 1; if I < Index'Last - 2 then Val(I + 1) := Shift_Left(U, 32 - Natural(I)); I := I + 2; else exit; end if; end loop; for N in 0..3124999 loop for J in Index'range loop S := S + Find_Highest_Bit(Val(J)); end loop; end loop; Set_Exit_Status(Exit_Status(S)); end Highest_Bit2; Jim Rogers