Message Boards Message Boards

0
|
855 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

About the efficiency of different functions doing the same thing

Posted 1 year ago

It's well known that in Wolfram language, one thing can always be done with many ways, e.g., the following one:

In[99]:= t1 = (200! // Timing)[[1]]
t2 = (Gamma[201] // Timing)[[1]]
t3 = (Product[i, {i, 200}] // Timing)[[1]]
t4 = (Fold[Times, Range[200]] // Timing)[[1]]
Sort[{t1, t2, t3, t4}]
Table[%[[i]]/%[[i - 1]], {i, 2, 4}]

Out[99]= 0.00001

Out[100]= 8.*10^-6

Out[101]= 0.000236

Out[102]= 0.000379

Out[103]= {8.*10^-6, 0.00001, 0.000236, 0.000379}

Out[104]= {1.25, 23.6, 1.60593}

As you can see, they can be very different in terms of efficiency. So how do I actually choose these different approaches for a particular thing?

Regards, Zhao

POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract