Mathematica Benchmarktest 
(Version 4)
created 27th of July 2003 by Stefan Steinhaus

Note : Version 4 of this benchmark test became necessary since the old version was old-fashioned and the timings were too low to be used seriously, most especially as Mathematica 5.0 is much faster then version 4.x. In the 4th edition of the benchmark test a lot of functions have been update but also several have been replaced by more complex functions. Please use this benchmark test only in connection with Mathematica 5.0 or higher.

Note: You should have a computer with at least 512MB of RAM and clock speed of more then 1 GHz to run this benchmark test.

Initialisation of global variables

$HistoryLength = 3;
SeedRandom[4711];
\(\(tm = {{"Test function", "Your computer", "AMD XP 2800+", "Factor"}, 
{"", "", ""}, 
{"Creation,trans.,resh. of a matrix", 0, 54.547, 
            0}, 
{"Sorting of values in asc. order", 0, 
            37.075, 0}, 
{"2200001!", 0, 20.265, 
            0}, 
{"Check for Mersenne prime numbers", 
            0, 36.032, 
            0}, 
{"Computation of Euler numbers", 0, 
            52.781, 0}, 
{"Creation of a Toeplitz matrix", 0, 41.782, 
            0}, 
{"Computation of Pi on 3.000.000 decimals", 0, 33.953, 
            0}, 
{"Comp. of Eigenvalues of matrix", 0, 
            51.89, 0}, 
{"Build an orthogonal and normalized set of a matrix", 0, 54.734, 
            0}, 
{"Numerical comp. of 6 triple integrals", 0, 60.234, 
            0}, 
{"FFT and inverse FFT over 2^23 random values", 0, 18.875, 
            0}, 
{"3-way ANOVA over 4 levels", 0, 
            69.813, 0}, 
{"Expansion of a huge polynomial", 0, 53.317, 
            0}, 
{"Comp. of a Laplace transformation", 
            0, 76.781, 
            0}, 
{"Comp. of 8 Koch Snowflakes", 0, 
            41.562, 0}, 
{"Array of Mandelbrot graphics", 0, 55.078, 
            0}, 
{"Graphics array with pipes and Klein bottles", 0, 22.687, 
            0}, 
{"Animation of a 3D Mountain in heatcolors", 0, 35.484, 
            0}, 
{"", "", ""}, 
{"Total timing:", 0, 0, 0}};\)\)

Misc. operation

Creation, trans. & reshaping of a 1000x1000 matrix

The following function creates a table of 1000x1000 real random numbers, takes the absolute value of them, transpose this matrix, flatten it to a list, partitions it to a 500x2000 matrix. The timing will be calculated for doing this proccess 150 times.

tm[[3, 2]]=Timing[
              Do[Transpose[
                    Partition[
                      Flatten[
                        Transpose[Abs[Table[Random[Real], {1000}, {1000}]]]], 
                      500]];, {i, 1, 150, 1}]] [[1]]/. Second -> 1;

20.000.000 values sorted in ascending order

The following function sorts a list of 20.000.000 random numbers and stores the timing for it.

a = Table[Random[Real], {20000000}];

tm[[4, 2]]=Timing[Sort[a];] [[1]]/. Second -> 1;
Clear[a];

Integer Computations

Simple mathematics

Computation of the factorial of 2.200.001.

tm[[5, 2]]=Timing[2200001!;] [[1]]/. Second -> 1;

Number Theory

Check for Mersenne prime numbers

The following function checks the first 5.000.000 numbers of the form x^2-1 whether they are a Mersenne prime number.

a := {};
tm[[6, 2]]=Timing[
              Do[If[PrimeQ[j^2 - 1], AppendTo[a, j^2 - 1]], {j, 
                  5000000}]][[1]]/. Second -> 1;

Clear[a];

Computation of Euler numbers

The following function computes a table with the first 260 Euler numbers of the polynomial n and stores only the timing.

tm[[7, 2]]=Timing[Table[
                  EulerE[n, x], {n, 0, 260}, {x, 0, 260}];][[1]]/. Second -> 1;

Linear Algebra

Computation of a 1000x1000 Toeplitz matrix

The following function computes 150 times a 1000x1000 Toeplitz matrix, a special diagonal form of an integer matrix. Afterward the timing of this computation will be stored.

tm[[8, 2]]=Timing[
              Do[Table[Abs[x - i] + 1, {i, 1, 1000}, {x, 1, 1000}];, {j, 
                  1, 150, 1}]][[1]]/. Second -> 1;

Floating Point Computations

Simple mathematics

The following functions calculates Pi on 3.000.000 digits behind the comma and stores the timing for it.

$MaxPrecision = Infinity;

tm[[9, 2]]=Timing[N[Pi, 3000000];][[1]]/. Second -> 1;

$MaxPrecision = 1. *10^6;

Linear Algebra

Computation of Eigenvalues of 1.500x1.500 matrix

The following function computes a 1.500x1.500 random matrix, computes the Eigenvalues and stores the time for it.

tm[[10, 2]]=First[
              Timing[Eigenvalues[
                  Table[Random[], {1500}, {1500}]]]][[1]]/. Second -> 1;

Build an orthogonal and nomalized set of a 800x800 matrix

The following function computes an orthogonal and normalized set of a 800x800 random matrix.

<< LinearAlgebra`Orthogonalization`

tm[[11, 2]]=Timing[GramSchmidt[
                  Table[Random[Real], {800}, {800}]];][[1]]/. Second -> 1;

Remove[LinearAlgebra`Orthogonalization]

Analysis

Numerical integration of 6 triple integrals

ℼ = N[π];

SetOpts[NIntegrate, o__?OptionQ] := (oni = Options[NIntegrate]; 
          SetOptions[NIntegrate, o]);

ResetOpts[NIntegrate] := 
        SetOptions[NIntegrate, Sequence @@ oni];

SetOpts[NIntegrate, PrecisionGoal -> 3];
tm[[12, 2]]=Timing[{
NIntegrate[
                  Sin[(x^2)] + Sin[(y^2)] + 
                    Sin[(z^2)], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, -ℼ, ℼ}], 
NIntegrate[
                  (2^Sin)[x] + (3^Cos)[y] + 
                    (4^Sin)[z], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, -ℼ, ℼ}], 
NIntegrate[
                  (2^Log)[(x^2) + (y^2) + (z^2)], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, 
                    0, ℼ}], 
NIntegrate[
                  Sin[(x^2) - (y^2) - 
                      (z^2)], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, -ℼ, ℼ}], 
NIntegrate[
                  Cos[(x^2) + (y^2) + 
                      (z^2)], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, -ℼ, ℼ}], 
NIntegrate[
                  Sin[(x^2) + (y^2) + 
                      (z^2)], {x, -ℼ, ℼ}, {y, -ℼ, ℼ}, {z, -ℼ, ℼ}]}][[1]]/. Second -> 1;
ResetOpts[NIntegrate];

FFT and Inverse FFT over 2^23 random values

tm[[13, 2]]=Timing[InverseFourier[
                  Chop[Fourier[
                      Table[Random[Real], {2^23}]]]];][[1]]/. Second -> 1;

Stochastic & statistic

3-way ANOVA with 4 levels

The following function computes an 3-way ANOVA with 4 levels over 30 random data sets.

<< Statistics`ANOVA`

tm[[14, 2]]=Timing[ANOVA[
                  Flatten[
                    Flatten[
                      Flatten[
                        Table[Table[
                            Table[Table[{j, h, g, Random[Real]}, {30}], {j, 
                                1, 4}], {h, 1, 4}], {g, 1, 4}], 1], 1], 
                    1], {factor1, factor2, factor3, All}, {factor1, factor2, 
                    factor3}];][[1]]/. Second -> 1;

Remove[Statistics`ANOVA]

Symbolic Computations

Expansion of a huge polynomial

polys = Table[x - a, {a, 1, 20, 0.006}];
tm[[15, 
            2]] = Timing[Expand[
                  Apply[Times, 
                    polys]];][[1]] /. Second -> 1;

Clear[polys];

Computation of a multi-dimensional Laplace transformation

tm[[16, 
          2]] = Timing[LaplaceTransform[
                  d Sin[(Sqrt[a t1]) + (Sqrt[a t2]) + (Sqrt[a t3]) + (Sqrt[a t4])], {t1, t2, t3, t4}, {s1, s2, s3, s4}, 
                  DefiniteIntegral -> 
                    True];][[1]] /. Second -> 1;

Graphics

2D Graphics

Computation of a Koch Snowflake

The boundary of the Koch Snowflake constructed by Helge Von Koch in 1904 is the union of three congruent self-similar fractals.  Each third of the snowflake is constructed by starting with one side of an equilateral triangle and performing an iterative process.  The following cell defines a function called Snowflake that illustrates the stages in this iterative process.

Programmcode

(*  \(Given\ a\ non - negative\ integer\ n, \ the\ function\ 

          \ \ \ \ Snowflake\ generates\ the\ nth\ level\ approximation\ 

          \ \ \ \ to\ the\ Koch\ Snowflake . \ 
              Code\ from\ the\ Notices\ of\ 

          \ \ \ \ the\ AMS\ Vol  .39\ #7\ Sept\ 92, \ page\ 709\)              *)
    
\(Clear[n, Snowflake, start, finish, doline]

      Snowflake[n_Integer?NonNegative] := 
\ \ Show[
          Graphics[
\ \ \ \ Nest[\ \((#1 /. 
                    Line[{start_, finish_}]\  :> 
                      doline[start, 
\ \ \ \ \ \ \ \ \ \ \ \ \ finish])\)\  &, 
\ \ \ \ \ \ \ \ \ \ {Line[{{0, 0}, {1/2, 
                      Sqrt[3]/2}}], 
\ \ \ \ \ \ \ \ \ \ \ Line[{{1/2, 
                      Sqrt[3]/2}, {1, 0}}], 
\ \ \ \ \ \ \ \ \ \ \ Line[{{1, 
                      0}, {0, 
                      0}}]}, 
\ \ \ \ \ \ \ \ \ \ n]], 
\ \ \ AspectRatio -> 
            Automatic, PlotRange -> All, DisplayFunction -> Identity]


      \(doline[start_, 
            finish_] := 
\ \ Module[{vec, norma}, 
\ \ vec = 
              finish - start; 
\ \ norma = 
              Reverse[vec]\ {\(-1\), 1}\ Sqrt[3]/6; 
\ \ {Line[{start, 
                  start\  + \ vec/3}], 
\ \ Line[{start\  + \ vec/3, 
                  start\  + \ vec/2\  + \ norma}], 
\ \ Line[{start\  + \ 
                    vec/2\  + \ norma, \ 
                  start\  + \ 2\ vec/3}], 
\ \ Line[{start\  + \ 2\ vec/3, \ 
                  finish}]
\ \ }
\ \ ];\)\)

Computation for 8 flakes

tm[[17, 2]]=Timing[Snowflake[8];][[1]]/. Second -> 1;

Mandelbrot graphics

Calculates an array of 9 MAndelbrot graphics.

Mandelbrot[z_, c_, n_:  20] := 
      Block[{res = (z^2) + c}, 
        If[Abs[res] > 2, n, 
          If[n < 1, 0, Mandelbrot[res, c, n - 1]]]]

tm[[18, 2]]=Timing[GraphicsArray[{{ContourPlot[
                        Mandelbrot[0, a + b I], {a, -2, 
                          1}, {b, -1.5, 1.5}, ContourLines -> False, 
                        PlotPoints -> 180, ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -2, -1}, {b, -0.5, 0.5}, 
                        ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.5, -1.2}, {b, -0.2, 
                          0.2}, ContourLines -> False, 
                        PlotPoints -> 180, ColorFunction -> Hue, 
                        DisplayFunction -> Identity]}, {ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.5, -1.45}, {b, -0.1, 
                          0.1}, ContourLines -> False, 
                        PlotPoints -> 180, ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.49, -1.45}, {b, -0.06, 0.06}, ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.49, -1.47}, {b, -0.06, 0}, ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity]}, {ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.49, -1.48}, {b, -0.05, -0.03}, ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.49, -1.488}, {b, -0.04, -0.03}, ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity], 
                      ContourPlot[
                        Mandelbrot[0, 
                          a + b I], {a, -1.49, -1.489}, {b, -0.038, -0.034}, ContourLines -> False, PlotPoints -> 180, 
                        ColorFunction -> Hue, 
                        DisplayFunction -> Identity]}}];][[1]]/. Second -> 1;

3D Graphics

Graphics array with pipes and Klein bottles

bx = 6 Cos[u] (1 + Sin[u]);
by = 16 Sin[u];
rad = 4 (1 - Cos[u]/2);
X = 
        If[π < u ≤ 2 π, bx + rad Cos[v + π], 
          bx + rad Cos[u] Cos[v]];
Y = 
        If[π < u ≤ 2 π, by, 
          by + rad Sin[u] Cos[v]];
Z = rad Sin[v];

tm[[19, 2]]=Timing[
              GraphicsArray[{{ParametricPlot3D[{{Sin[t], u, Cos[t]}, {Sin[t], 
                          Cos[t], u}, {u, Sin[t], Cos[t]}}, {t, -Pi, 
                        Pi}, {u, -Pi, Pi}, PlotPoints -> 400, 
                      DisplayFunction -> Identity], 
                    ParametricPlot3D[{{Sin[t], u, Cos[t]}, {Sin[t], Cos[t], 
                          u}, {u, Sin[t], Cos[t]}}, {t, -Pi, Pi}, {u, 0, 
                        2  Pi}, PlotPoints -> 400, 
                      DisplayFunction -> Identity], 
                    ParametricPlot3D[{X, Y, Z}, {u, 0, 2 π}, {v, 0, 
                        2 π}, PlotPoints -> {220, 220}, 
                      Axes -> False, Boxed -> False, 
                      ViewPoint -> {1.4, -2.6, -1.7}, 
                      DisplayFunction -> Identity]}, {ParametricPlot3D[{X, Y, 
                        Z}, {u, 0, 2 π}, {v, 0, 2 π}, 
                      PlotPoints -> {220, 220}, Axes -> False, 
                      Boxed -> False, 
                      ViewPoint -> {1.4, -1.6, -1.7}, 
                      DisplayFunction -> Identity], 
                    ParametricPlot3D[{{Sin[t], u, Cos[t]}, {Sin[t], Cos[t], 
                          u}, {u, Sin[t], Cos[t]}}, {t, -Pi, 
                        Pi}, {u, -2 Pi, 0}, PlotPoints -> 400, 
                      DisplayFunction -> Identity], 
                    ParametricPlot3D[{{Cos[t], Pi - Sin[t], u}, {u, 
                          Pi - Sin[t], Cos[t]}, {Pi - Sin[t], u, 
                          Cos[t]}}, {t, -Pi, Pi}, {u, -Pi, Pi}, 
                      PlotPoints -> 400, 
                      DisplayFunction -> Identity]}}]][[1]]/. Second -> 1;

Clear[x, y, z, bx, by, rad]

Animations

3D Mountain in heatcolors

The following function will calculate an animation of a figure with heat colors.

<< Graphics`Graphics3D`

tm[[20, 2]]=\(\(Timing[
              Do[ShadowPlot3D[\ 
                  Exp[\(-z\)*\((x^2\  + \ 
                          y^2)\)], 
\ \ \ \ \ \ \ \ \ \ \ \ \ {x, \ \(-2\), \ 2}, \ {y, \ \(-2\), \ 2}, 
                  PlotPoints -> 
                    50, 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ShadowPosition\  -> \ 
                    1, DisplayFunction -> Identity], {z, 0.1, 1, 
                  0.004}]]\)[\([1]\)]\)/. Second -> 1;

Remove[Graphics`Graphics3D]

Final results of the Benchmarktest

Display Benchmark results on screen

In this section a final analyze of the benchmark timings will be done. Information like the version of Mathematica, all resulting timings, the sum of the timings and a comparison timing will be displayed.

tm[[22, 2]] = 
        Sum[tm[[i, 2]], {i, 3, 20, 1}];
tm[[22, 3]] = 
        Sum[tm[[i, 3]], {i, 3, 20, 1}];
Do[
        tm[[i, 4]] = tm[[i, 3]]/tm[[i, 2]], {i, 3, 20, 
          1}];
tm[[22, 4]] = 
        tm[[22, 3]]/tm[[22, 2]];
Print["Mma. version   = ", $Version];
Print["\nTimings in seconds:\n", "===================\n\
"];
Print[TableForm[tm]];

Save Benchmark results in a file

\(\(\(
\)\(strm = 
      OpenWrite["c:\benchmatheresult.txt"]

    Do[
	
      WriteString[strm, tm[\([x, 1]\)], ";", 
        N[tm[\([x, 2]\)], 4], "
"], {x, 3, 20, 1}]

    WriteString[strm, tm[\([22, 1]\)], ";", 
      N[tm[\([22, 2]\)], 4]]

    Close[strm]\)\)\)

Feedback for Benchmark site

Dear Mathematica user in case you would like to add your Mathematica benchmark timings to the benchmark website then send the following information by email to stefan@steinhaus-net.de

Either copy & paste the timing table or send the output file "benchmatheresult.txt"

Information about the computer you have used: Model type, processor (amount or processors, if more then one), clock speed, RAM, cache size

Mathematica version number

Your name and email address