- Sum 10 million numbers.
- Matrix multiplication (A * AT), where A is a (10000, 5000) matrix.
- Cholesky decomposition.
- SVD decomposition of a (10000, 2000) matrix.
- PCA of (10000, 2000) matrix.
- Determinant of a (2500, 2500) matrix.
- Inverse of a (1600, 1600) matrix.
- Languages:
- Python (conda)
- built-in functions
- manual loop
- NumPy
- Julia (official installer)
- built-in functions
- manual loop
- R (official installer)
- built-in functions
- manual loop
- MATLAB
- built-in functions
- manual loop
- Octave (homebrew)
- built-in functions
- manual loop
- Python (conda)
- Hardware: Fixed to my MacBook Pro 2014 running the latest macOS
- Backends: Use the defaults for each language, but vary some parameters if possible (e.g. MKL vs. Apple Accelerate, number of threads)
- Measuring timing: use built-in functions where available, otherwise use tic/toc variants
x = rand(1, 1e7); timeit(@() sum(x))
% file sum1.m in the working directory function s = sum1(x) s = 0; for e = x s = s + e; end end
timeit(@() sum1(x))
import random x = [random.uniform(0, 1) for _ in range(10**7)] %timeit sum(x)
def sum1(x): s = 0 for e in x: s += e return s
%timeit sum1(x) import numpy as np x = np.array(x) %timeit np.sum(x)
julia> using BenchmarkTools julia> x = rand(10^7) julia> @benchmark sum($x)
function sum1(x) s = 0.0 for e in x s += e end s end
julia> @benchmark sum1($x)
octave:1> x = rand(1, 1e7); octave:2> z = []; octave:3> for i = 1:1000, tic; sum(x); z = [z; toc]; end octave:4> mean(z) octave:5> z = [] octave:6> tic; sum1(x); toc;