2

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Dominic Michaelis
  • 889
  • 1
  • 7
  • 18
  • 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. – Dr. belisarius Apr 01 '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 01 '13 at 15:32
  • 1
    Here's one way to tell in any particular case which of two (or more) functions is faster: http://mathematica.stackexchange.com/questions/22419/benchmarking-expressions/22420#22420 – bill s Apr 01 '13 at 17:47

0 Answers0