signum of long

R

Roedy Green

Hmm, 9th candidate is here:

return (int)( diff >>> 32 ) | ( (int)diff | (int)diff << 1 ) >>> 1;


wibble2 in now ascribed to piotr under the name kobzda.

public static final int kobzda ( long diff )
{
// the beauty of this method is most of the work is in int,
not long
// which works well on 32-bit machines.
return (int) ( diff >>> 32 ) | (int)diff >>> 1 | (int)diff &
1;
}

Poiter has onother algorithm he called signHalf

public static final int signHalf ( long diff )
{
return ( diff <= 0 ) ? (int) ( diff >>> 32 ) : 1;
}
 
P

Piotr Kobzda

You have missed my advice. This one is my next candidate. :))
Following the code carefully, you should see the difference...

Your benchmark (version 1.1) has *eight* candidates (not nine).
I've added my new candidate (9th in the collection) under the name
"piotr" into your benchmark, the results are in my previous post.


Regards,
piotr
 
R

Roedy Green

Hmm, 9th candidate is here:

return (int)( diff >>> 32 ) | ( (int)diff | (int)diff << 1 ) >>> 1;
I have added this 9th candidate into the mix as piotr.
I will be posting the new results in a bout 30 minutes
 
R

Roedy Green

You have missed my advice. This one is my next candidate. :))
Following the code carefully, you should see the difference...

Look at the latest version with two of your entries. See
http://mindprod.com/jgloss/benchmark.html

The fastest overall is the piotr algorithm under Jet. It is four times
faster than on Java 1.5 client.

The results are much less reproducible than I would have expected. I
don't know why. I shut everything down I could.

IF you want to run the benchmark, you can download it by clicking
download. Post the result of the latest version on your hardware if
it reasonably different from mine or if your results differ
significantly. see http://mindprod.com/contact/equipment.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top