Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Recently I have been solving some Project Euler problems. I find there are always several ways to do the same thing. For example, one could join two lists like this:

a = {2, 1};
b = {2, 3};
Union[a, b]
Join[a, b]

Which gives

{1, 2, 3}
{2, 1, 2, 3}

So the Union function sorts the element and deletes duplicates. I guess the Join function will be faster, but how much faster? In a loop, would it be more efficient to use Join and DeleteDuplicates at each 100th step?

Is there documentation of the comparative performance of Mathematica functions? Because heuristics as above could be totally wrong, and I don't know how much experimenting it would take to form a good understanding of the complexity of functions.

share|improve this question
3  
Performance tuning in Mathematica is more complicated than that. Start a fresh kernel and try {Timing[Prime[10000000000]][[1]], Timing[Prime[10000000000]][[1]]}. Also, many of the algorithms use heuristics to switch between strategies when appropriate. –  belisarius Apr 1 '13 at 15:21
3  
Your specific question is so highly specialized that I doubt you will find an answer no matter how much performance documentation might exist. To get an accurate answer, you will need to do a quick timing study in your particular circumstance. –  whuber Apr 1 '13 at 15:32
1  
Here's one way to tell in any particular case which of two (or more) functions is faster: mathematica.stackexchange.com/questions/22419/… –  bill s Apr 1 '13 at 17:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.