Questions tagged [performance-tuning]

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.

Filter by
Sorted by
Tagged with
9 votes
1 answer
98 views

Arithmetic operations on NumericArrays

Currently, NumericArrays are directly supported by the most important array-related functions, what makes them a very attractive data structure for implementing ...
user avatar
1 vote
2 answers
63 views

Timing for generating long matrix

I need a code for thermodynamics research that generates a matrix of 32768 by 32768 elements. The code is the followng: ...
user avatar
13 votes
11 answers
760 views

Partitioning a list based on a criterion for sublists

SeedRandom[1]; alist = RandomInteger[{1, 10}, 20] {2, 5, 1, 8, 1, 1, 9, 7, 1, 5, 2, 9, 6, 2, 2, 2, 4, 3, 2, 7} I would like to divide this list into sublists (...
user avatar
  • 14.8k
23 votes
6 answers
800 views

What secrets are hidden away in your init.m file and where do you place it? Please do share!

Help Build init.m Best Practices By Sharing or Critiquing Code Some of our most essential code is hidden away in a file that we can just drop and forget. Although contents of this infamous file should ...
11 votes
1 answer
240 views

Association vs Pair - Creation performance, Selection performance

Suppose that we ...
user avatar
  • 2,451
3 votes
1 answer
151 views

How to speed up the calculation of recurrence formula?

I have a recurrence formula. How to quickly solve P[1] to p[49]? ...
user avatar
  • 107
1 vote
0 answers
71 views

sometimes Select / sometimes Position is faster

As you see, For list L, L1(Select method) is slower than L2(Position method). But for list <...
user avatar
  • 2,451
13 votes
4 answers
588 views

Monitoring Apply / @@@ over large lists

How to monitor and/or print partial progress of Apply, e.g. f @@@ list? I have found answers using Map (e.g. this nice trick using Echo, or this general trick), but ...
user avatar
  • 233
5 votes
1 answer
374 views

Fast double sum involving Kronecker symbol

I have three lists $$A=\{\alpha_1...\alpha_N\}$$ $$B=\{\beta_1...\beta_N\}$$ $$M=\{M_1....M_N\}$$ In practice $\alpha_i$ and $\beta_i$ are complex numbers with modulus smaller than 1. The $M_i$s are ...
user avatar
  • 912
8 votes
1 answer
264 views

Working around Memory Leak from HermiteDecomposition

I am running into an issue where HermiteDecomposition seems to leak memory, but only from certain matrices ...
user avatar
0 votes
1 answer
65 views

get positions satisfying multiple criteria

Given a list L. It is mathematically proven that there is no element in L matching 2 or more patterns in ...
user avatar
  • 2,451
5 votes
4 answers
200 views

Solving equation over TruncatedDistribution (FindRoot)

I'm trying to solve the following equation : ...
user avatar
0 votes
1 answer
72 views

Parallelize for loop in mathematica

I have the following code which essentially consists of a first for loop that iterates through a very large number of rows and a small for loop that iterates through a small number of columns. The ...
user avatar
  • 111
2 votes
1 answer
117 views

Speed Up the Gelman-Rubin-History function

A bit of background information I have created a function to calculate the convergence of the Gelman Rubin diagnostic (useful in Bayesian analysis). The function seems to work as I want, however I ...
user avatar
2 votes
0 answers
96 views

Nested numerical integration strategies

I have the following space time integral ...
user avatar
  • 320
5 votes
1 answer
91 views

K-Mean Clustering Algorithm

I have implemented the k-Means Clustering Algorithm using the Wolfram Language. However, I think it can be more efficient. Do you have any idea how to make it more efficient (e.g., by removing the ...
user avatar
4 votes
3 answers
192 views

Implementing fast linear search for perfect vertical image alignment

After experimenting with image alignment aprroaches presented here and here and some other approaches involving ImageDistance and ...
user avatar
1 vote
1 answer
70 views

Selecting edges for a random geometric graph in an arbitrarily shaped domain

I have some code to generate a random geometric graph in a domain of specificed shape (here an H-shape). Edges cannot exist when they intersect the domain boundary (so we need line of sight for edges ...
user avatar
  • 1,505
1 vote
1 answer
49 views

Performance tuning joinAcross (my version)

I have written what I think is a more or less complete version of JoinAcross with code below. I've done this to try to avoid the misbehavior I've observed in the ...
user avatar
  • 572
2 votes
2 answers
96 views

Efficient alternatives to a Table based iteration

I have performed some operations using the Table iterator but I am looking for efficient alternatives to my approach. First, some preliminary code: ...
user avatar
  • 187
4 votes
2 answers
183 views

Speeding up the Kuramoto model on a random graph

I am solving the Kuramoto model on a random graph $G(n,p)$, plotting the synchrony against the coupling parameter, as follows, ...
user avatar
  • 1,505
3 votes
0 answers
54 views

Parallel Evaluation Stops Evaluating Without Warning Message

This is my full code ...
user avatar
1 vote
0 answers
65 views

Find Max Instance Over Permutations

I would like to find the maximum of some objective function over all possible permutations ...
user avatar
9 votes
2 answers
366 views

Why AppendTo is much faster than Table for tracking object movement

I need to track some objects, the simplified version something like this ...
user avatar
  • 6,510
7 votes
1 answer
419 views

Tuples optimization challenge

Consider a function that for a given integer $0\le n <256$ computes the number of leading zeros in its binary representation. ...
user avatar
  • 15.7k
3 votes
1 answer
127 views

How to optimize ContourPlot3D evaluation?

I tried to plot a certain 3D sine function: ContourPlot3D[(Sin[x^2] + 2) * (Sin[y^2] + 2) * (Sin[z^2] + 2) , {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] but ran into an ...
user avatar
  • 333
0 votes
0 answers
75 views

Is any attempt to implement by hand built-in functions reasonable?

There are a lot of functions that are related to numerical computation of integrals, numerical solutions of algebraic/differential equations, etc. In such functions there a lot of different methods (...
user avatar
0 votes
1 answer
94 views

Help with optimization of Reduce/Solve function

I have a set of vectors in $3$D as shown below, ...
user avatar
  • 270
6 votes
1 answer
139 views

Fast integration of ElementMeshInterpolation[]-functions

In this simplified example I consider a small FEM-mesh ...
user avatar
2 votes
0 answers
44 views

Free up used Memory

When using FunctionCompile[] to generate a large matrix of ranges there seems to be no way of recovering memory even though the variables are either out of scope or overwritten. I am aware that there ...
user avatar
  • 101
1 vote
1 answer
101 views

Recursive relationship too slow

Writing: ...
user avatar
  • 4,281
2 votes
0 answers
29 views

How To Speed Up Looping TimeSeriesModelFit?

I need to apply 'TimeSeriesModelFit' to successive subsets of a long list. A small scale example of this is given here. ...
user avatar
6 votes
6 answers
312 views

Grouping consecutive elements at specified positions

Let L1={1,2,4,6,8,9,10,14,15,17,21,22,72,76,80,96,106,116,117} Question1) Group from 10-th to 14-th elements in L1. So that the ...
user avatar
  • 2,451
1 vote
1 answer
155 views

Need to find a unique mathematical expression (not in documentation) that is as short as possible but takes a good amount of time to evaluate

I am writing a public ResourceFunction and I need a good clever use case that should not appear to emulate any examples in the official documentation but will ...
user avatar
  • 1,787
0 votes
0 answers
103 views

Why is this 3D sine plot taking so much RAM?

I'm using the online version in the Wolfram Cloud. Whenever I attempt the following computation: ...
user avatar
  • 333
1 vote
0 answers
20 views

Why does Sparsearray diagonalization by Krylov technique become slower for very large sizes?

Here is an example sparse matrix, taken from example Hamiltonian, which was a question I asked before in this forum. ...
user avatar
6 votes
2 answers
458 views

How to quickly test if two regions intercept?

If I randomly generated two cylinders, how do I test if they intercept? For example: ...
user avatar
  • 123
2 votes
4 answers
249 views

Applying f for a part of list (MapAt is slow)

Suppose that there are 2000 stones in a row. You should grind 1000 of them to make beads. The time loads(making beads) for each stone are similar. But which 1000 stones? case1) the first 1000 stones. ...
user avatar
  • 2,451
0 votes
0 answers
18 views

How to apply NetDecoder on each element in output?

I try to apply the NetDecoder on each output element but get an error. ...
user avatar
8 votes
1 answer
199 views

Speediest Julia Set "By Hand"

While being aware of the built-in command, I would like to show my students how the Julia set is actually generated. The code I came up with is slow, even though I am quite happy with the picture it ...
user avatar
  • 283
5 votes
3 answers
244 views

ParallelDo barely faster than Do

I am new to parallel computing, so I am trying to get a grasp as to how this works. Many posts seem to indicate that overhead (like here) is a common pitfall, but I do not see why this would be the ...
user avatar
  • 951
9 votes
3 answers
650 views

Faster determination if two nodes are connected in a graph

In the code below connectedQ[g_,v1_,v2_] is a function to check if two nodes v1 and v2 in ...
user avatar
  • 1,750
3 votes
1 answer
70 views

How To Compile The Computation Of Cumulative Returns

I'm trying to compile this function, specifically the second line which computes the cumulative return of 100 daily returns. ...
user avatar
3 votes
3 answers
794 views

Why does this take so long time to run?

How do you improve the speed of this? It took me more than 10 minutes and is still running. I want to gather them in pair of inverse elements. ...
user avatar
  • 1,750
4 votes
2 answers
345 views

Multiplication of one big integer and a long list of integers - fast

This is an example of multiplying a big integer to a list of integers. ...
user avatar
  • 2,451
1 vote
2 answers
74 views

Theoretical Timing possible? (not changes for each evaluation)

Is there a method to measure theoretic time load (hope +theoretic memory load) of an evaluation? They should not change - always generate same value after pressing Enter key(=evaluation). Hope they ...
user avatar
  • 2,451
5 votes
1 answer
242 views

Lazy vs strict evaluation approaches - performance comparison

In general, I think there are two methods of evaluating a variable in Mathematica. My question is about performance of the two methods. Suppose that our final goal is to evaluate ...
user avatar
  • 2,451
2 votes
2 answers
77 views

Optimising eigenvalue matrix calculation

I'm quite new to mathematica and am trying to figure out how to optimise my code as currently it takes a very long time to compile and makes it hard to bug test. The first part that creates the graph ...
user avatar
1 vote
2 answers
384 views

How To Make Monte Carlo Simulation Run Faster

I'm running a Monte Carlo simulation of stocks prices in which the data that is used to define the Skewed Normal Distribution updates after 1,000 simulations. Thus it is crucial that I get this code ...
user avatar
0 votes
0 answers
41 views

RegionMeasure works very slow for BooleanRegion

Consider two regions: ...
user avatar
  • 3,544

1
2 3 4 5
53