As of May 31, 2023, we have updated our Code of Conduct.

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
1 vote
0 answers
69 views

How do I profile my own code in Mathematica? [duplicate]

Coming from the question Profiling from Mathematica and reading the example, I manage to reproduce it but I have no idea how to adjust it to profile my own code. Given an example file: ...
infinitezero's user avatar
  • 1,232
1 vote
3 answers
202 views

Plotting Poincare section

I am trying to plot the Poincare section. Is there any other method where I get results faster? I use Table to find points at an integer multiple of \phi, making NDSolve evaluate the solution for ...
SanGu's user avatar
  • 21
0 votes
1 answer
62 views

How to improve performance of making an Exponentially Weighted Correlation Matrix?

I would like to make an Exponentially Weighted version of Correlation (similar to https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.ewmcov.html)....
IntroductionToProbability's user avatar
9 votes
7 answers
744 views

How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

I would like to make a rectangular array of 1 and 0 with continuous columns of 1. We are ...
IntroductionToProbability's user avatar
4 votes
1 answer
134 views

Is it possible to improve efficiency of the function?

I have the following function scriptQ to check whether an expression is a "script" or not. This function is frequently called by others, so I need to ...
Lacia's user avatar
  • 1,695
0 votes
0 answers
60 views

May the runtime of a code compiled in C depend on the C compiler used?

I have a Windows machine with installed Mathematica. I compile the code in C. The compiler I use is CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler from ...
John Taylor's user avatar
  • 4,864
3 votes
2 answers
155 views

Optimizing execution time and exploring closed form solutions in Mathematica's DSolve

I am encountering two issues while running the following code in Mathematica: Slow execution: I have been running the code for approximately 30 minutes, but it is still executing. I am using Windows ...
internet's user avatar
  • 229
0 votes
1 answer
63 views

Speed up compoundReturn across an array

I am trying to calculate a moving-window of compounded returns on a large 2D-array. (ie some kind of MovingMap on geometric returns) The Rows are time-steps and the Columns are different financial ...
IntroductionToProbability's user avatar
1 vote
0 answers
49 views

Increase computation speed for nested integral equations

I want to numerically solve these two nested integral equations $$q(J_0,T)=\int_{-\infty}^{\infty} \frac{1}{\sqrt{2\pi}}e^{-\frac{z^2}{2}}\,\mbox{tanh}^2\left(\frac{z\sqrt{q(J_0,T)}+J_0 m(J_0,T)}{T}\...
Giancarlo Creanza's user avatar
1 vote
1 answer
64 views

Evaluate the function once in the following compiled code, or optimize it?

Consider the following Switch function for two variables: ...
John Taylor's user avatar
  • 4,864
0 votes
0 answers
65 views

Why is the slowdown of the compiled code evaluation so significant?

Edit I have reduced the powers of trigonometric functions entering formula1, formula2 to make the problem clearer. It seems that ...
John Taylor's user avatar
  • 4,864
16 votes
1 answer
605 views

Fast Hankel Function in Mathematica

I am working on a project that requires repeated calls to HankelH1[0, r] for $r$ spanning the full real axis. When I use the mathematica routine, it can be as much ...
JonBean's user avatar
  • 163
1 vote
2 answers
117 views

What is the best (fastest and accurate) way to obtain PDF from the given dataset?

Consider some list of two coordinates, points, generated by some arbitrary function function1 (which is a pdf up to a ...
John Taylor's user avatar
  • 4,864
3 votes
1 answer
72 views

Compile`GetElement for tensors of rank 1 and 2

Consider some data momvals, mzvals and functions phVal, ...
John Taylor's user avatar
  • 4,864
0 votes
1 answer
51 views

ParametricPlot takes longer time while working with root objects

I have the following Mathematica code: ...
codebpr's user avatar
  • 713
7 votes
5 answers
323 views

Quickly simulating "mean-time until collision"

Edit high-level summary of problem/solutions in Mathematica community post Suppose I draw (with replacement) $k$ colored balls from bins with probabilities $h_1,\ldots,h_d$ until some color is drawn ...
Yaroslav Bulatov's user avatar
3 votes
2 answers
134 views

Non-uniform birthday problem in Mathematica

Suppose my year has $d$ days. I have a vector of probabilities of being born on those days as $h=p_1,\ldots,p_d$, and want to estimate the smallest $k$ such that probability of of birthday collision (...
Yaroslav Bulatov's user avatar
2 votes
0 answers
47 views

Most efficient way to define several local constants in a function -- Block or nested Withs?

Sorry if this is kind of a noob question but I'm wondering what the best-performing approach is to the following: I'd like to define several local constants in the body of a function, each of which ...
max's user avatar
  • 61
2 votes
1 answer
91 views

How to quickly make the following action with the table?

Consider the following two tables: tab1 = RandomReal[{1, 2}, {10, 4}]; tab2 = RandomReal[{2, 3}, {10, 6}]; and "charges" each representing the ...
John Taylor's user avatar
  • 4,864
0 votes
0 answers
40 views

Optimization of conditions applying

Let we have some data generator, e.g. lazy tuples or permutations. I need to select data by some conditions cond1, cond2, …, up to 5-6 conditions. All of them need ...
lesobrod's user avatar
  • 859
1 vote
0 answers
44 views

Why returning the counter takes much time in the following example?

Consider the following data and analytic expressions: ...
John Taylor's user avatar
  • 4,864
3 votes
2 answers
200 views

About how to speed up in assignment

I would like to know if there is a way for increasing the speed of the following computation: I have a list, let's call it list, and another list of values, val. I ...
Benigno's user avatar
  • 31
2 votes
1 answer
68 views

Why the following formula slows down the compiled code?

I made a routine code CodeComp2 that performs algebraic evaluations using some data TablexgridWithEx, ...
John Taylor's user avatar
  • 4,864
0 votes
0 answers
76 views

Speeding up a dynamic vector plot

I would like to create a vector plot with a solution such that the vector plot is based on an underlying parameter en that I can adjust. With the help of Click in a vector plot to plot several ...
Ben Lou's user avatar
4 votes
0 answers
35 views

Efficiently threading with a default value for missing parts / defining custom behavior for addition of expressions with a given head

In short, I would like to be able to "add" expressions with a particular head (call it h for our purposes) which will always appear with a sequence of (...
max's user avatar
  • 61
4 votes
2 answers
274 views

How to speedup the integration of a tabulated function?

The problem Consider some pre-generated list with coordinates x1,x2,x3,x4 and values of some function ...
John Taylor's user avatar
  • 4,864
5 votes
5 answers
804 views

How can I make the following table quickly?

Consider a table Tabb = RandomReal[{0, 1}, {3, 2}]; I want to make the following table: ...
John Taylor's user avatar
  • 4,864
2 votes
2 answers
109 views

Multiply a table with a sub-table of another table

Consider two grids of coordinates: grid1 = Flatten[Table[{i, j}, {i, 1, 15}, {j, 1, 20}], 1]//N; grid2 = Flatten[Table[{0.5 i, 0.5 j}, {i, 1, 45}, {j, 1, 60}], 1]; ...
John Taylor's user avatar
  • 4,864
0 votes
0 answers
42 views

Speed up Select Operating on a Large List with Multiple Criteria

I am using the following code to select stocks that have performance data starting before one specified date and ending after a second specified date, as follows: ...
Jonathan Kinlay's user avatar
0 votes
0 answers
68 views

How to prevent Mathematica from maximum CPU usage?

I have a high-demanding Mathematica task that uses Compile and turns on parallelization. While evaluating, it always consumes around 100% of CPU. Could you please tell me how to reduce the maximal ...
John Taylor's user avatar
  • 4,864
1 vote
0 answers
48 views

Comparing performance of `ParallelMap` with pure function

Test data are here: q = CloudGet[ "https://www.wolframcloud.com/obj/874e3b18-808a-404a-aaa0-4e3ad1ac4668"]; I construct interpolation and an equi-...
atapaka's user avatar
  • 3,609
2 votes
1 answer
105 views

Fastest way to find position of elements in a list

I need to identify the position inside list of the elements in target. Straightforward solution: ...
Albercoc's user avatar
  • 926
3 votes
2 answers
154 views

Speed up dot product with shifted vector

I have to calculate multiple dot products between a vector and consecutive part of another (longer) vector, shifted at certain number of elements. Naive implementation takes about 0.1 seconds. ...
Vsevolod A.'s user avatar
3 votes
2 answers
194 views

Fitting an exponential system

Consider the following system over a periodic array, where $1\leq j\leq n$, $$ y_j= \sum_{k=0}^m \frac{e^{-\sum_{|i|\leq k}(k-|i|)x_{j+i}}-e^{-\sum_{|i|\leq k}(k+1-|i|)x_{j+i}}}{\sum_{|i|\leq k} x_{j+...
sam wolfe's user avatar
  • 4,233
3 votes
2 answers
117 views

Efficient method (maybe parallel method) to calculate a 256$\times$256 matrix?

I want to calculate a matrix of shape 256$\times$256 as follows ...
narip's user avatar
  • 321
0 votes
1 answer
76 views

Improve performance of DeleteDuplicates for list of matrices

I have a matrix $A_0[x,y,z]$ and a list of matrices $B$ with about 30 matrices. Matrix $A_0$ is a function of some parameters $x,y,z$. I create a new list of matrices, say $A_1$ produced by ...
AG1123's user avatar
  • 539
1 vote
0 answers
43 views

How to optimize the code of drawing a region?

...
Ulysses Zhan's user avatar
1 vote
1 answer
85 views

How to express the argument through the function?

I would like to express argument $d$ through $f$ and $B$ and to get $d(f,B)$ $$f(d,B)=B\left(\left(\frac{1}{4}-\frac{d}{B}\right)\left( 1-\left(1- e^{-30d/B} \right)^8\right)+\frac{2/B}{3+1/B^2}\left(...
Mam Mam's user avatar
  • 1,383
6 votes
0 answers
109 views

Using `Real32` numbers in Mathematica?

Is it possible to use Real32 format in Mathematica for matrix operations and does it make sense for performance? For high-dimensional vectors, high precision is an ...
Yaroslav Bulatov's user avatar
3 votes
2 answers
450 views

How to produce the following table faster?

Question Consider a toy function func[x1,x2,x3,x4] and a toy grid gridTot of the coordinates ...
John Taylor's user avatar
  • 4,864
3 votes
2 answers
344 views

How can I speed up calculation of the integral?

Is it possible to speed up the calculation of the Kx integral? ...
Mam Mam's user avatar
  • 1,383
3 votes
1 answer
113 views

Compiling a function that uses MapThread

I'm looking for tips on quickly applying the following update to $B$ pairs of $(w_i,x_i)$ $$\text{step}(w_i,x_i)=w_i-a x_i \langle w_i, x_i \rangle$$ Below is a readable but very slow version ...
Yaroslav Bulatov's user avatar
6 votes
1 answer
113 views

Minimizing computational time for a quantum walk problem

Any suggestions as to how to speed up the computational time for this quantum walk problem which is coded using a normalized SparseArray coin operator as follows: ...
thils's user avatar
  • 3,178
8 votes
5 answers
275 views

Values of counting functions

I have a table of integers, say A, and consider the counting function C, which, for a given x, gives the number of elements in A which are less or equal to x. Next, I want to plot C(x) in some range, ...
Maciej Ulas's user avatar
1 vote
1 answer
69 views

How to speedup integration of interpolated function with logarithmized data?

Consider some dataset corresponding to the grid x1, x2, function[x1,x2]: ...
John Taylor's user avatar
  • 4,864
8 votes
2 answers
2k views

Why does Mathematica take so long to produce this sound?

Mathematica is behaving very slow, but it is not like I could compare, as the speed has always been like this. The following ran in 58.64 seconds. Is this normal? How can I speed it up? ...
Aarav Prasad's user avatar
0 votes
0 answers
21 views

Smoothening noisy distributions to learn eigenvalue statistics

I have a problem involving random matrices, in which I'm trying to learn properties of their spectral statistics. The problem I'm having can be boiled down to a list management issue, but I will begin ...
miggle's user avatar
  • 647
16 votes
4 answers
601 views

Speeding up Gaussian sampling

Edit Greg Hurst answers show how to independently get 3x speed-up using single-threaded MKL implementation and 4x speed-up by using native implementation with multi-threading, can they be combined? ...
Yaroslav Bulatov's user avatar
1 vote
1 answer
63 views

How to speedup calling the interpolation function? [duplicate]

Consider the following data: ...
John Taylor's user avatar
  • 4,864
2 votes
1 answer
115 views

Compile a code evaluating a condition only if another condition is positive

Consider the following three tables: ...
John Taylor's user avatar
  • 4,864

1
2 3 4 5
57