[PLUG] Re: [PJUG Javamail] Re-resolved: OT: Formula For Determining # Of Digits . . .

Travis Brooks travis_brooks at hotmail.com
Fri Feb 18 21:43:10 UTC 2005


well, at the risk of sounding really really geeky, aw what the heck its 
friday...

Joe's method pointed out 2 things that my code was doing that poorly 
effected performance, namely promoting an int to a long and making a method 
call for the absolute value instead of inlining it.  If you change the top 
couple of lines of my original method to:

if(val==Integer.MIN_VALUE)
    return 10;
int absVal = val>0?val:(val * -1);

then it about doubles the speed.  When testing on a random array of 1 
million ints my method came up consistently faster, but for whatever reason 
at 10 million ints Joe's slightly edged mine out.  I wondered if this might 
be an artifact of java.util.Random relying on the crappy old Knuth random 
algorithm, so I did the test again using 
cern.jet.random.engine.MersenneTwister from the Colt library (If you haven't 
used a Mersenne Twister before, check it out!) to fill in the array.  The 
results almost to the millisecond reversed, so Joe's beat my method at 1 
million ints and i came out on top at 10 million.

I think i'm going to call it a tie...and will immediately cease my beating 
of this poor dead horse...

-travis

Give a man a fish and he eats a fish, but teach a man to fish at rock-bottom 
wages and we all shall eat his fish.




>From: Jon LeVitre <jonlevitre at yahoo.com>
>To: javamail at pjug.org, plug at lists.pdxlinux.org
>Subject: Re: [PJUG Javamail] Re-resolved: OT: Formula For Determining # Of 
>Digits . . .
>Date: Fri, 18 Feb 2005 11:07:17 -0800 (PST)
>MIME-Version: 1.0
>Received: from java.solidware.com ([208.187.226.104]) by 
>mc4-f16.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Fri, 18 Feb 2005 
>11:40:45 -0800
>Received: from java.solidware.com (localhost [127.0.0.1])by 
>java.solidware.com (8.12.9/8.12.9) with ESMTP id j1IJe161026031;Fri, 18 Feb 
>2005 11:40:01 -0800 (PST)
>Received: from web52710.mail.yahoo.com (web52710.mail.yahoo.com 
>[206.190.39.161])by java.solidware.com (8.12.9/8.12.9) with SMTP id 
>j1IJ9A61025494for <javamail at pjug.org>; Fri, 18 Feb 2005 11:09:10 -0800 
>(PST)
>Received: (qmail 57383 invoked by uid 60001); 18 Feb 2005 19:07:18 -0000
>Received: from [208.51.234.122] by web52710.mail.yahoo.com via HTTP; Fri, 
>18 Feb 2005 11:07:17 PST
>X-Message-Info: yilqo4+6kc6UhgIl2ngCtNYlfCJcIsH655/TppjzPHg=
>Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
>DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;  s=s1024; d=yahoo.com;  
>b=d2UTymq9mbBmxKuSqDZmVzvt3qlmgB/GFIDGRZNFd4EuUmVyKg49zGUJnTufgwhkj+35Wq/LWP3XdHtduAgUffTp7XAZs6hkU183trZ7uSeMwpVM5Er5kPe0deIseFW9KFHKStWBT0ajBsbF5w3S4e1UQJPCEec8o0CJrBt+Ucw= 
>  ;
>Errors-To: javamail-admin at pjug.org
>X-BeenThere: javamail at pjug.org
>X-Mailman-Version: 2.0.11
>Precedence: bulk
>List-Help: <mailto:javamail-request at pjug.org?subject=help>
>List-Post: <mailto:javamail at pjug.org>
>List-Subscribe: 
><http://www.pjug.org/mailman/listinfo/javamail>,<mailto:javamail-request at pjug.org?subject=subscribe>
>List-Id: PJUG - Portland Java User's Group Mail List <javamail.pjug.org>
>List-Unsubscribe: 
><http://www.pjug.org/mailman/listinfo/javamail>,<mailto:javamail-request at pjug.org?subject=unsubscribe>
>List-Archive: <http://www.pjug.org/pipermail/javamail/>
>Return-Path: javamail-admin at pjug.org
>X-OriginalArrivalTime: 18 Feb 2005 19:40:45.0304 (UTC) 
>FILETIME=[BD0DFF80:01C515F1]
>
>
>--- Joe Sam Shirah <jshirah at attglobal.net> wrote:
>
> >
> >     Hi Travis,
> >
> > > But by far the *fastest* method i could think up was this one...
> >
> >     My thoughts exactly.  I hadn't posted before because I was
> > going to do the timing tests first, but I'm happy to take your
> > word for it.  Following is my version, which should be faster
> > overall, assuming a random distribution of input values.
>
>It will depend on the distribution or your data, but if the data is
>random, Travis's method will be more efficient.
>
>Keep in mind that about 53% of random 32 bit ints are 10 digits.  Of
>the remaining values 90% are 9 digits, 9% are 8 digits, .9% are 7
>digits, etc.
>
>You don't get much leverage by checking whether a number is > 99999,
>because like 99.995% are.
>
>Jon
>
>
>
>__________________________________
>Do you Yahoo!?
>Read only the mail you want - Yahoo! Mail SpamGuard.
>http://promotions.yahoo.com/new_mail
>_______________________________________________
>Web Site - http://www.pjug.org/
>Javamail mailing list
>Javamail at pjug.org
>http://www.pjug.org/mailman/listinfo/javamail





More information about the PLUG mailing list