# Benchmarks

# Benchmarks

This page will provide benchmarks between Sage and Mathematica, please check back periodically as I am still in the process of determining the best way to benchmark each application while ensuring fair comparisons.

## System Used

### Hardware

- HP Pavillion dv2000
- Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz
- Memory: 2Gb

### Software

- Operating System: Linux - OpenSuse 11.0 (x86) Kernel: 2.6.25.16-0.1-pae
- Sage Version: Version 3.1.2, Release Date: 2008-09-19
*(Note: If a benchmark uses a newer version of Sage the version will specified with the benchmark)* - Mathematica Version: 6.0.2.1

## Benchmarks

### Contour Plots

Comparison of Sage and Mathematica's Contour Plot functions.

Function Plotted:

X Range: -3,3

Y Range: -3,3

Benchmarks are based on the average execution time of 100 calls to the Contour Plot Function.

#### Sage

##### Code

times = [] for i in range(0,100): t1 = time() pl = contour_plot(y^2 - x^3 + x, (-3,3),(-3,3),fill=False,contours=0,plot_points=num_points) t2 = time() times.append(t2 - t1)

##### Comparison with different number of points plotted

The Sage contour_plot function takes a plot_points parameter which specifies " the number of points to plot in each direction of the grid." The chart below shows the execution time of contour_plots with plot_points values ranging from 100 to 600 at 100 point increments.

** Results **

Points Execution Time in Seconds 100 0.0482304501533508 200 0.0869896674156189 300 0.153420553207397 400 0.242804827690125 500 0.360980730056763 600 0.493348760604858

#### Mathematica

##### Code

time = Timing[ Do[ContourPlot[y^2 - x^3 + x, {x, -3, 3}, {y, -3, 3},Contours -> {0}, ContourShading -> False], {a, 0, 100}]]

**Results**

*Average Execution Time:* 0.0516832 seconds

#### Side by Side

Since Mathematica doesn't have parameter for number points to plot in the grid it makes a completely accurate comparison impossible. Subjectively however with plot_points in Sage set to 100 you get a picture of the same visual quality as with Mathematica's.

Sage with plot_points=100: Avg Execution Time: 0.0482304501533508 seconds

Mathematica: Avg Execution Time: 0.0516832 seconds

#### Interpretation

While it would be a mistake to assume from these benchmarks that Sage's contour plot is faster than Mathematica's. It does point to the conclusion that the difference in performance between the two functions is minimal.

### Factoring Integers

Comparison of Sage's **factor** function and Mathematica's **FactorInteger** function.

Note: Using Sage Version 3.2.1

#### Sage Code

t1 = time() factor( val ) t2 = time() print t2 - t1

#### Mathematica Code

Timing[FactorInteger[val]]

#### 50 Digit Integers

*First Value:* 1934830109234738389299110111002010010027213211173

**Times:**

Sage: 0.191963911057

Mathematica: 0.368024

*Second Value:* 5223742730473248747591023429843298492835092582481

**Times:**

Sage: 0.0329298973083

Mathematica: 0.004

*Third Value:* 2348172983123812382173987894732567643276473646343

**Times:**

Sage: 1.05752491951

Mathematica: 1.85212

#### 75 Digit Integers

*First Value:* 12093434274949817483748923743748732489734873847384738297489237483274823744

**Times:**

Sage: 87.9907610416

Mathematica: 111.299

*Second Value:* 92394892301893143256458324935465418124832974265687348465723012392392733473

**Times:**

Sage: 5.50352191925

Mathematica: 1.09607

*Third Value:* 50982472839478916416453643410109192831273987194673611347834632456123894327

**Times:**

Sage: 38.9131929874

Mathematica: 237.883

#### Results

For both the sample 50 and 75 digit integers Sage was faster 2 out of the 3 times. However most cases the difference is small especially when considering the simplicity of the benchmark.

There were a couple interesting results:

For the second 75 digit integer Sage was almost 5.5 times slower than Mathematica.

For the third 75 digit integer Mathematica was approx. 6 times slower than Sage.

**Note:** Sage results were obtained using the PARI Package, PARI uses the *number field sieve* algorithm for integer factorization. I'm not sure if Mathematica also uses the *number field sieve* algorithm.