Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting types - which is faster?  RSS feed

 
Angela Truce
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!