Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

learn more… | top users | synonyms (2)

27
votes
0answers
452 views

Why is StringExpression faster than RegularExpression?

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
17
votes
0answers
637 views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
14
votes
0answers
288 views

What Mathematica features and idioms have n^2 complexity or worse

Here are a few: AppendTo[data, elem], Sort[data, test], in some cases use of ___ (as ...
11
votes
0answers
808 views

Mathematica performance on Mac

I recently got a trial version of both Mathematica 9 and MATLAB 13a for Windows. I was stunned by the performance difference in the Windows and the Mac version. It was a simple test in matrix ...
10
votes
0answers
115 views

Exp is slower for some number ranges

I get a hit on performance with the Exp function depending on the range of my inputs. for example, with: ...
7
votes
0answers
171 views

Improving the performance of a package for working with rational functions

As Mathematica gets slow for large symbolic calculations, the cost of putting terms over a common denominator (Together), in particular, gets too high. It occurred ...
7
votes
0answers
256 views

Faster simplification of linear combinations of some specific functions

After some profiling I've found that my program spends most of its time in the simplification step. The program uses my simplification function many times (over different data). My calculation is not ...
7
votes
0answers
243 views

Using Compile to speed up Function with PermutationProduct

I have the following fairly simple routine dot involving PermutationProduct that I wish to speed up using ...
6
votes
0answers
51 views

Issuing user-defined messages takes a long time (Message is slow)

Issuing messages takes a very long time in version 9 and version 10. Can others reproduce this? Is there a fix? Update: This is slow only when using the front end, but not when running the kernel ...
6
votes
0answers
197 views

Performance tuning - Explicitly set Mathematica use Nvidia GPU for rendering

I feel hesitated to ask this question, but I cannot figure out a way to increase the performance. The problem is about running this featured example on a computer with both Intel HD GPU and Nvidia ...
6
votes
0answers
230 views

Poor CUDALink performance, when calling a kernel multiple times

When working on a project of mine I noticed that CUDALink shows very poor performance when calling CUDA kernels multiple times in a loop-construct. To demonstrate this I put together this little ...
6
votes
0answers
84 views

Slow NIntegrate over complicated domains (sometimes)

Overview I have a very large matrix I need to calculate where each element requires the integration of a product of two functions over some complicated domain. I would like to find a set of options ...
6
votes
0answers
97 views

Compiled function crashes kernel when trying to list over different length arguments

I'm trying to speed up a tally/binning operation that I have to run many times. I have many lists of between 1 and 10 numbers from the range [1,5] and I want to ...
6
votes
0answers
201 views

Speeding up multilinear PRA branch-and-bound algorithm with worst-case exponential time scenario with respect to basic events

The algorithm is a branch-and-bound algorithm that calculates dominances for PRA, probalistic risk assessment. The task was to find faster ways to do it in numerical software such as Matlab but we ...
6
votes
0answers
455 views

Optimizing NIntegrate for higher PrecisionGoal

By default, NIntegrate works with MachinePrecision and its PrecisionGoal is set to ...
5
votes
0answers
84 views

Is there something like MaxProcessorUsed?

For standard procedures it is easy to test if the implementation is better or worse than other by using Timing etc. It does not help us with creating ...
5
votes
0answers
72 views

Does one need to be careful about loading multiple (many) contexts or packages in the same session?

I have a number of large pieces of precomputed data which I am considering putting into individual packages in order to load them (via DeclarePackage) and unload ...
5
votes
0answers
84 views

Faster way to perform SameQ[Reduce[…], Reduce[…]]

I'm have some expressions that I need to confirm the equality of. SameQ[Reduce[...], Reduce[...]] works like a charm for the more simple expressions, however when ...
5
votes
0answers
206 views

Parallelizing is much slower than single kernel evaluation?

Starting with a vector of matrices, tVec, I would like to parallelize the multiplication of each element with the same matrix ...
5
votes
0answers
863 views

MathKernel.exe capped to use only 13% of CPU?

I am using a Windows machine with 8 cores. No other process than Mathematica 8 is using CPU time right now - still the MathKernel.exe CPU usage does not go beyond 13%. My current computation takes ...
4
votes
0answers
119 views

Efficient Generation of Subgraphs (or, unfriend a friend a day)

NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above. My friends ...
3
votes
0answers
57 views

Listable on first level

I have some function which take List as input. f[l_List]:=someActions[l] I need apply this function to a list of lists. Now I ...
3
votes
0answers
67 views

Fast principal component analysis

I'd like to speed up a principal value value analysis. The data contains a large set of vectors with a large dimension. Both are in the range of 1000. I want to obtain the loadings matrix for further ...
3
votes
0answers
64 views

Efficient processing of Special Ordered Sets with LinearProgramming

I'm playing with integer linear programming, especially problems involving lots of constraints which would appear to be special ordered sets. Below is a toy example, three last rows of the matrix ...
3
votes
0answers
151 views

Understanding performance: graph connected components

I need to analyze directed graphs with 10M edges, 1M vertices, and 300K strongly connected components, so that the largest one contains 400K vertices. I read some explanations of Leonid Shifrin here, ...
3
votes
0answers
114 views

What can I do to improve the performance of my calculations?

I'm trying to express a simple probability problem in Mathematica, but am having trouble getting my calculations to execute at a reasonable speed. I have an object whose unknown location is modeled ...
3
votes
0answers
67 views

LibraryLink parallel performance

I'm trying to use a LibraryLink function in parallel. It is an embarrassingly parallel problem, so that no dependency between those parallel tasks. However I can only get the parallel efficiency about ...
3
votes
0answers
108 views

“Off-label use” of Mathematica functions for performance

Assisting an acquaintance with a simulation where a very large number of binomial probability calculations are required, I pointed them to a slightly obscure function to dramatically speed up their ...
2
votes
0answers
61 views

Why does setting $Assumptions make my Fourier transforms slow?

Consider these Fourier transforms ...
2
votes
0answers
221 views

Taking real and imaginary parts of indexed functions and speeding up ComplexExpand

I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts. I am ...
2
votes
0answers
89 views

Speed improvement in string distance function

I'm using this distance function to compare distance between strings: ...
2
votes
0answers
110 views

Force Dispatch to generate dispatch tables

Dispatch creates hash tables only for lists of length larger than 3. Is there any way to force MMA to create hash tables even for lists of length smaller than 4? ...
2
votes
0answers
196 views

why version 9 is much slower than version 8 in producing these graphics

Consider this example(taken from Thomas's question here) ...
2
votes
0answers
168 views

Speeding up a numerical constrained quadratic optimization

I'm trying to solve a quadratic optimization problem in 35 variables, $\vec{α} = \left< α_1, \ldots, α_{35}\right>$: $$ \begin{aligned} &\operatorname*{maximize}_\vec{α}&&1.0\cdot ...
2
votes
0answers
99 views

Significant platform-dependent efficiency when importing data?

I'm curious, as I understand that answer this way: If you are using a Linux derivative or something like cygwin on Windows, then this is an efficient solution for reading only the third field ...
2
votes
0answers
264 views

FindRoot - Speed and errors

I am using FindRoot[] to solve a complicated equation. It seems I get the correct answer even though I get errors about an ...
1
vote
0answers
136 views

Speeding Up Image Processing Functions

I am working with stacks of 1024x1024 timelapse microscopy images that I am performing a series of image processing functions on to help segment each image. These functions include ...
1
vote
0answers
98 views

Speeding up NDSolve for system of differential equations

I am wondering if there is a way to speed up this function that solves a system of ordinary differential equations with NDSolve? Thus far I've tried specifying a few different methods such as LSODA, ...
1
vote
0answers
82 views

Speeding up the numerical integration of a certain function

I'm using the following function f[t_] := 3/4 t^-3 NIntegrate[(x^4*Csch[x/2]^2), {x, 0, t}, Method -> {Automatic, "SymbolicProcessing" -> 0}]; I ...
1
vote
0answers
84 views
1
vote
0answers
38 views

A more efficient way of fitting a non-linear model that returns an entire list?

I have a function that takes two parameters, del and nu, and returns a list npoints long ...
1
vote
0answers
111 views

How to tweak the following purely numerical code

I am using the following numerical function in my program and I would like to speed it up. ...
1
vote
0answers
67 views

Linear interpolation over 2 variables

I'm tuning a function to data over 4-5 variables using Differential Evolution. The objective function calls frequently interpolation function. I came to a point, where compiling the objective function ...
1
vote
0answers
245 views

Solve[] unexpectedly giving empty solution sets for extremely large problems

I was calculating the set of lattice vectors in $\mathbb{Z}^4$ which have taxicab norm $r$. For example, executing ...
1
vote
0answers
103 views

Sum slowing down computations

I am trying to compute higher order Casimir invariants for some representations of certain groups. I can get the quadratic, cubic and quartic but beyond that things are taking too long to the point I ...
1
vote
0answers
74 views

Is the TCPIP link type compressed?

Since I'm already piping a MathLink connection in a ssh tunnel (connect back is a pain!), I wonder if it makes sense to compress the data in the stream (ssh -C). As ...
1
vote
0answers
453 views

How can I speed up numerical integration of multidimensional integral?

I am numerically solving an integral equation that contains a double integral. I have managed to get a solution but it takes forever. I am wondering if there is a way to speed up numerical integration ...
0
votes
0answers
113 views

Improving the speed of evaluating Table with nested functions

I am a Mathematica novice working with a stack of 1024 x 1024 WatershedComponents (or MorphologicalComponents) label matrices ...
0
votes
0answers
76 views

strange timing behavior

The following code is from a book about Mathematica. ...