Forums Register Login

Sorting types - which is faster?

+Pie Number of slices to send: Send
Hello,

this is just out of general interest to find out if anyone knows if there is any speed difference between sorting doubles and integers? Technically you could pass an integer as a double but if you treat the integer as a double does this decrease the speed in anyway because it has to sort the numbers after the period?

I am basing my assumption that you use the compareTo method.

thanks.
[ August 12, 2006: Message edited by: Angela Truce ]
+Pie Number of slices to send: Send
compareTo() can only compare objects; therefore we might be talking about Integers and Doubles, but not ints and doubles. The best way to sort arrays of genuine ints or doubles would be the sort() methods in the java.util.Arrays class.

Which would be faster? It really depends on the underlying hardware, but in general, you shouldn't see much of a difference.

Note that converting between int and double is not free, and probably much slower than any time difference between comparing instances of the two types.
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2509 times.
Similar Threads
explain the out put
Floting point processing and speed
Sorting java.lang.objects
need help using StringTokenizer
Type inference in generic mehods
Sorting of Strings in a UserDefined Way
compareTo with generic objects!
System.out.println()....need explanation
Simple J2SE 5.0 Tiger Notes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:47:14.