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
6 votes
6 answers
327 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,877
1 vote
1 answer
168 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,837
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
459 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
253 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,877
0 votes
0 answers
19 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
9 votes
1 answer
217 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
  • 293
5 votes
3 answers
247 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
  • 1,043
9 votes
3 answers
688 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
  • 2,084
3 votes
1 answer
74 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
817 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
  • 2,084
4 votes
2 answers
349 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,877
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,877
5 votes
1 answer
246 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,877
2 votes
2 answers
80 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
389 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
42 views

RegionMeasure works very slow for BooleanRegion

Consider two regions: ...
user avatar
  • 3,832
0 votes
1 answer
95 views

Code refinement - bottleneck

In the code, I indicated a fragment (picker =...) where the program is slow for large m=n=dim (for example)=2000. Does anyone have any idea what to replace it with ...
user avatar
  • 969
0 votes
1 answer
133 views

Performance improvement of array setup and processing

I need to improve the speed of the following algorithm: Take a list $x={x_1,...x_n}$. For each integer $i=1,..n$ construct the following list assuming $z=x_i$ if $i=1$ and $z=x_{i-1}$ otherwise: $X_i=...
user avatar
1 vote
1 answer
140 views

Brute force graph transformations

I have a list of list of pairs of integer that for me represents a list of graphs with n nodes. For example with n=5 I could ...
user avatar
0 votes
2 answers
100 views

Memory preserving computation in chunks

I would like to do the following: Make a table tab1={{i1,b1,c1,d1},{i1,b1,c1,d2},...,{i1,b1,c2,d1},...,{i1,b2,c1,d1},...{i2,b1,c1,d1},...} for the given range imin < i < imax. Make some ...
user avatar
  • 3,832
8 votes
3 answers
651 views

How to clear up RAM without exiting kernel?

I am trying to implement the code which generates some table, works with it, extracts some numbers, add them to some other table, then clears the table (only the table and not the other elements of ...
user avatar
  • 3,832
3 votes
2 answers
111 views

Anyway to make financial indicators run/compute faster?

For stock data (closeData) going back from 2010 to 2022 it takes roughly .2 seconds for this code to run. That is way too slow for my purposes. Is there anyway I can speed this up using a C compiler ...
user avatar
0 votes
1 answer
80 views

Vectorise IF statement

I would like to perform an iteration on a list, component-wise. The iteration is time consuming and it would be hence beneficial to be able to stop it once an element of the list has reached a ...
user avatar
1 vote
0 answers
40 views

I am searching for the Eigen stuff of a non linear transformation

I have a slightly odd problem I have been working on as part of a project on probability models. The full problem itself is not relevant but here is where I am stuck. I have a 6D space $P$, where all ...
user avatar
4 votes
0 answers
67 views

Efficiently calculating half of the eigenvectors of a sparse array

Eigenvectors of a sparse array $\quad$ Problem statement I want to calculate the eigenvectors corresponding to the negative eigenvalues of an $8L^2 \times 8 L^2$ matrix ($L \sim 30 )$. Most of the ...
user avatar
0 votes
0 answers
43 views

How to set up precision by default?

I have a table computing many numbers with large precision. Because of this, probably, Mathematica consumes a lot of RAM. Is it possible to restrict the precision in any calculations by default (...
user avatar
  • 3,832
0 votes
0 answers
55 views

Best way to run multiple calculations simultaneously?

I feel this question probably has been asked before, but I can't find a thread with a clear enough answer. Let me know if you can help locate anything useful. As the title suggests, I want to run ...
user avatar
  • 4,124
2 votes
2 answers
186 views

Is there a better way to build a matrix with position coordinates conditions?

Suppose that I have a list of coordinates {x,y} following some geometry in space, for example ...
user avatar
1 vote
1 answer
77 views

Faster PowersRepresentation using IntegerPartitions

Earlier I posted a question about taking fast integer square roots of known integer perfect squares. The reason this came up is I was trying to find a faster way of mimicking the PowersRepresentations[...
user avatar
  • 495
2 votes
1 answer
255 views

Fast Integer Square Roots of known perfect squares?

A bit of a generic question perhaps - say I have a list of non-negative integers and I know each are perfect squares - what is a fast way of finding their square roots? I have very long lists (...
user avatar
  • 495
1 vote
3 answers
104 views

Optimizing operations between vectors

Basically I am generating a grid in space (so a vector where v[[1]]=position 1 in x) and a random number of particles in space (so a vector where p[[1]]= position of particle 1 on space). Afterwards, ...
user avatar
  • 21
6 votes
2 answers
377 views

Fastest way to create multiple lists in a do loop

I do not think my explicit code will be helpful to illustrate it so here is the "barebones" silly example: ...
user avatar
  • 635
1 vote
0 answers
68 views

Dividing list into smaller list using a set of rules?

Suppose we have the list for $n\in\mathbb{N}$ Range[1,n] We choose the number in the list where $x=1$, $x=n$ and $x=1+(n-1)/2$ round closest to and the numbers ...
user avatar
  • 199
4 votes
1 answer
190 views

Speeding up Fourier transform and eigenvector calculation

I have a matrix $M$ in Bloch basis (momentum space). Then I have to take Fourier transform of $M$ to go to real space. The size of this lattice in real space can be fixed to some value $N_{unit}$. ...
user avatar
  • 601
4 votes
4 answers
68 views

How to create a function that merges the first $n$-digits of each value in a list?

Suppose we have a list of numbers. For example, A={1231,1232,1233,1241,1236} Using a function f[x,A], I want to rearrange this ...
user avatar
  • 199
11 votes
2 answers
430 views

NIntegrate: the order of singular points matters!

Consider the following integral: $$I = \int_{-5}^5 \frac{1}{(x(x-2))^{1/3}} dx.$$ The exact value is 6.30249 - 2.2405 I. I will perform ...
user avatar
11 votes
3 answers
181 views

Faster searching for subsets with pairwise conditions

I am looking for a faster way of finding large subsets of lists that obey pairwise conditions. In particular, I'm looking for a large (over 10k) set of quaternary words (i.e. ordered lists) of length ...
user avatar
  • 30.5k
1 vote
1 answer
39 views

NIntegrate With Singularity: Experiment With Various Parameters

I want to numerically evaluate the integral $$I = \int_{\mathbb R^2} dxdy f^*(x) f(y) K(x-y)dxdy,$$ where $$f(x) = \sqrt{\frac 2 \pi} e^{ikx} e^{-x^2}, \quad k\in\mathbb R$$ is an exponentially ...
user avatar
0 votes
1 answer
76 views

How to analyse the performance of Mathematica on this function?

Using f[n_] := Sum[1/(Sqrt[k] + Sqrt[k + 1]), {k, 1, n}] to analyze the well-know series... I noticed a sudden performance drop (on my outdated PC hardware ) ...
user avatar
1 vote
1 answer
45 views

Strange behavior of NIntegrate: small change of integration range give tremendous running time difference!

I have an integrand: integrand = E^((6*I)*x - x^2 - (6*I)*y - y^2)/(2 Pi (-I (I/100 + x - y))^(1/3)) This function decays as $\sim e^{-x^2-y^2}$ for $x,y \to \...
user avatar
1 vote
1 answer
49 views

Why each iteration takes longer than previous one when using VariationalD in this loop?

I have a function $f$, and I would like to modify it iteratively to approach another one called $a$ (not because I think this is the best way to do anything, but for experimentation). For this, I use <...
user avatar
  • 137
0 votes
0 answers
47 views

Alternative for PowerRepresentations[n, x, 1]

I am looking for numbers $n$ that can be written as the sum of other numbers. So: PowersRepresentations[n, x, 1]. But is there a faster way of finding these numbers?...
user avatar
  • 1,723
1 vote
1 answer
134 views

Explicit integration of PDE running very slowly

I would like to solve the PDE $\frac{\partial u}{\partial t}=(1-x)\frac{\partial u}{\partial x}$, in the interval $[0,1]$, with initial condition $u(0,x)=e^{-218(\frac{-2}{3}-ln(1-x))^2}$, by manually ...
user avatar
  • 199
3 votes
0 answers
90 views

Solving or Minimizing the Norm of the matrix equation $M^TAM - M^TB - B^TM =C$

I am trying to solve the matrix equation $M^TAM - M^TB - B^TM=C$ where I know A, B and C. My unknown matrix is M which has the special form that all the rows and columns sum to zero. i.e. I have four ...
user avatar
  • 495
5 votes
2 answers
154 views

ListDensityPlot with RegionFunction takes too long?

I am using ListDensityPlot with RegionFunction (MMA12.3 on Win 64) but it takes too long ...
user avatar
0 votes
2 answers
136 views

How can I exclude specific region in ListDensityPlot

I would like to exclude the region outside the yellow Polygon in this plot, how can I do that? ...
user avatar
4 votes
1 answer
151 views

How can I speed up processing with DeleteCases?

I would like to get points that are only inside a region. Here are the region and unfiltered points: ...
user avatar
5 votes
2 answers
142 views

How to guide Eliminate or GroebnerBasis to reduce a set of simple odes to a single ode (which can be done by Laplace Transform)

Recently, I am trying to use Eliminate or GroebnerBasis to simplify a system of ODEs. I don't want the solution of ODEs. What I ...
user avatar

1
2
3 4 5
54