Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 33363 invoked from network); 28 Apr 2007 14:26:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Apr 2007 14:26:26 -0000 Received: (qmail 17859 invoked by uid 500); 28 Apr 2007 14:26:32 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 17814 invoked by uid 500); 28 Apr 2007 14:26:31 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 17803 invoked by uid 99); 28 Apr 2007 14:26:31 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Apr 2007 07:26:31 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [209.133.199.10] (HELO jimsys.jagunet.com) (209.133.199.10) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Apr 2007 07:26:24 -0700 Received: from [127.0.0.1] (localhost [127.0.0.1]) by jimsys.jagunet.com (Postfix) with ESMTP id 6D6FC6B8354; Sat, 28 Apr 2007 10:26:01 -0400 (EDT) In-Reply-To: <4d45da050704262014r26d16b62q371fb4ee8b8a6c7d@mail.gmail.com> References: <46311BB5.3010507@haxent.com.br> <4d45da050704262014r26d16b62q371fb4ee8b8a6c7d@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <5794CE79-E5D3-4308-9DD2-7AEF9F30E60D@jaguNET.com> Cc: Davi Arnaut , lucian.grijincu@gmail.com Content-Transfer-Encoding: 7bit From: Jim Jagielski Subject: Re: [PATCH] vformatter cleanups (related to PR 42250) Date: Sat, 28 Apr 2007 10:26:00 -0400 To: APR Development List X-Mailer: Apple Mail (2.752.2) X-Virus-Checked: Checked by ClamAV on apache.org On Apr 26, 2007, at 11:14 PM, Lucian Adrian Grijincu wrote: > in apr-conv10-faster.patch you added: > > static const char digits[] = "0123456789"; > *--p = digits[magnitude % 10]; > > Why is this faster than: > *--p = (char) '0' + (magnitude % 10); ? > > For your "faster" version, under the hood, the C compiler adds > (magnitude % 10) to the address of digits and then copies the contents > of the memory location represented by the sum's result into *--p. > > My version just adds (magnitude % 10) to '0' and stores the result > in *--p. > Basically, the "faster" version would not be, assuming the cast isn't that expensive... This was run on an old FreeBSD box, and, ymmv, the ratios have proven to be pretty constant on other systems and implementations (for those of us old-timers, the biggest "surprise" may be that floating point is no longer costly): % ./cputimes Operation Clicks for each trial Mics/N Null Loop (n=10000000) {} 7 8 6 8 9 0.01 Int Operations (n=10000000) i1++ 7 8 8 8 7 0.00 i1 = i2 + i3 8 8 8 8 9 0.00 i1 = i2 - i3 9 10 10 9 8 0.00 i1 = i2 * i3 8 10 9 8 9 0.00 i1 = i2 / i3 46 46 47 46 46 0.03 i1 = i2 % i3 47 46 46 47 46 0.03 Float Operations (n=10000000) f1 = f2 8 7 8 8 8 0.00 f1 = f2 + f3 8 8 9 7 9 0.00 f1 = f2 - f3 9 8 8 9 8 0.00 f1 = f2 * f3 8 7 8 8 8 0.00 f1 = f2 / f3 40 41 40 40 40 0.03 Numeric Conversions (n=10000000) i1 = f1 69 70 69 70 69 0.05 f1 = i1 11 11 11 11 11 0.00 Integer Vector Operations (n=10000000) v[i] = i 21 21 23 21 22 0.01 v[v[i]] = i 46 47 47 47 47 0.03 v[v[v[i]]] = i 48 47 48 47 47 0.03 Control Structures (n=10000000) if (i == 5) i1++ 10 11 8 9 10 0.00 if (i != 5) i1++ 10 9 8 9 10 0.00 while (i < 0) i1++ 9 9 8 8 11 0.00 i1 = sum1(i2) 17 18 17 18 18 0.01 i1 = sum2(i2, i3) 19 20 19 20 19 0.01 i1 = sum3(i2, i3, i4) 24 23 24 23 24 0.01 Input/Output (n=1000000) fputs(s, fp) 34 34 34 34 35 0.26 fgets(s, 9, fp) 27 27 27 27 27 0.20 fprintf(fp, sdn, i) 110 108 109 109 109 0.85 fscanf(fp, sd, &i1) 159 158 159 163 158 1.24 Malloc (n=1000000) free(malloc(8)) 75 74 75 75 74 0.58 push(i) 51 51 53 54 53 0.40 i1 = pop() 27 28 28 28 28 0.21 String Functions (n=10000000) strcpy(s, s0123456789) 52 52 53 52 53 0.04 i1 = strcmp(s, s) 7 9 6 9 9 0.00 i1 = strcmp(s, sa123456789) 26 25 23 23 24 0.01 String/Number Conversions (n=100000) i1 = atoi(s12345) 4 3 4 4 3 0.28 sscanf(s12345, sd, &i1) 20 19 19 20 19 1.51 sprintf(s, sd, i) 9 9 10 9 9 0.71 f1 = atof(s123_45) 3 3 3 3 3 0.23 sscanf(s123_45, sf, &f1) 20 19 19 20 19 1.51 sprintf(s, sf62, 123.45) 29 29 30 30 29 2.29 Math Functions (n=1000000) i1 = rand() 9 9 9 10 9 0.07 f1 = log(f2) 18 17 18 18 17 0.13 f1 = exp(f2) 30 29 29 30 29 0.22 f1 = sin(f2) 18 17 18 17 18 0.13 f1 = sqrt(f2) 12 11 12 12 11 0.08 Total Seconds: 48.34