Instantly share code, notes, and snippets.

# r9y9/gap_benchmark.jl

Last active Jun 13, 2017
GaP-NMF short benchmark scripts for Python and Julia.
 push!(LOAD_PATH, ".") using BNMF using PyCall # bp_nmf のコードと比較するために、librosaを使う @pyimport librosa function spectrogram() x, ss = librosa.load("test.wav", sr=16000) X = abs(librosa.stft(x, n_fft=1024, hop_length=256)) return X end function test_gap(X) srand(98765) p = GaPNMF(X, K=100) fit!(p, epochs=100, verbose=true) nothing end function benchmark(N) X = spectrogram() elapsed = Array(Float64, N) for i=1:N tic() test_gap(X) elapsed[i] = toc() end println("Mean elapsed time: \$(mean(elapsed))") end benchmark(10) versioninfo()
 # -*- coding: utf-8 -*- import gap_nmf import librosa import numpy as np import scipy import time def spectrogram(): x, _ = librosa.load('test.wav', sr=16000) X = np.abs(librosa.stft(x, n_fft=1024, hop_length=256)) return X def test_gap(X): obj = gap_nmf.GaP_NMF(X, K=100, seed=98765) score = -np.inf for i in range(100): obj.update() # obj.figures() lastscore = score score = obj.bound() improvement = (score - lastscore) / np.abs(lastscore) print('iteration {}: bound = {:.2f} ({:.5f} improvement)'.format( i, score, improvement)) def benchmark(N=100): X = spectrogram() elapsed = [] for n in range(N): s = time.clock() test_gap(X) e = time.clock() - s elapsed.append(e) print(e) print("Mean elapsed time:", np.mean(elapsed)) benchmark(10) np.show_config() scipy.show_config() librosa.show_versions()
Owner Author

Owner Author

### r9y9 commented Aug 20, 2014

 2014/08/20 手元のmacbook airで計算した結果 Julia: Mean elapsed time: 21.92968243 Python: Mean elapsed time: 18.3550617 Juliaの方が1.2倍くらい遅い結果になった
Owner Author

### r9y9 commented Aug 20, 2014

 ``````In [1]: import scipy s In [2]: scipy.__version__ Out[2]: '0.14.0' In [3]: import numpy In [4]: numpy.__version__ Out[4]: '1.8.2' `````` 一応めもっておく。あんま意味ないかもだけど…
Owner Author

### r9y9 commented Aug 20, 2014

 `test.wav` -> https://github.com/r9y9/BNMF.jl/blob/master/notebook/arayuru.wav
Owner Author

### r9y9 commented Aug 22, 2014

 Devectorize.jl とか NumericExtentions.jl とか、@inbounds とかソートアルゴリズム変えるとか、その他もろもろ試したけど速くならなくてつらい
Owner Author

### r9y9 commented Aug 22, 2014

バージョン情報まとめ：

Juliaはちょうど最近0.3.0が出たので、0.3.0にしました

## Mac OS X 10.9.4

Julia Version 0.3.0
Commit 7681878* (2014-08-20 20:43 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.3.0)
CPU: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3

## Ubuntu 14.04 LTS

Julia Version 0.3.0
Commit 7681878 (2014-08-20 20:43 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM)2 Duo CPU E7400 @ 2.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Penryn)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3

Owner Author

### r9y9 commented Aug 22, 2014

 ubuntu で実行した結果 ``````Julia: Mean elapsed time: 27.035485086199998 [sec] Python: Mean elapsed time: 38.5021166 [sec] `````` juliaのほうが1.2倍速かった
Owner Author

### r9y9 commented Aug 22, 2014

 はい、lapackがubuntuには入っていませんでした。lapackを入れてからnumpy, scipyをインストールし直した結果： ``````Python Mean elapsed time: 21.8907655 `````` 38.5 sec. -> 21.9 sec. （約1.75倍の高速化） lapackつよい
Owner Author

# まとめ

• Juliaも結構速いけど、numpy, scipyはやはりつよい

## Mac OS X

``````Julia: Mean elapsed time: 21.92968243
Python: Mean elapsed time: 18.3550617
``````

## Ubuntu 14.04

``````Julia: Mean elapsed time: 27.035485086199998
Python: Mean elapsed time:  21.8907655
``````

## TODO

• Ubuntuのjuliaが遅い理由を調べる。fortranかgcc/g++によるものかなぁと踏んでる
• Juliaのコンパイルオプションをいじって検証
Owner Author

### r9y9 commented May 8, 2015

 今の自分ならjuliaのコードをめっちゃ速くできる自信があるけど、（続く
Owner Author

## Ubuntu 16.04

### Julia

``````Mean elapsed time: 14.6447493191

Julia Version 0.7.0-DEV.565
Commit d3db312* (2017-06-13 07:52 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
WORD_SIZE: 64
BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Prescott)
LAPACK: liblapack
LIBM: libopenlibm
LLVM: libLLVM-4.0.0 (ORCJIT, skylake)
``````

### Python

``````Mean elapsed time: 33.2673037
blas_mkl_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
blas_opt_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_mkl_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_opt_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_mkl_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_opt_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
blas_mkl_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
blas_opt_info:
library_dirs = ['/home/ryuichi/anaconda3/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/ryuichi/anaconda3/include']
INSTALLED VERSIONS
------------------
python: 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

librosa: 0.5.1

audioread: installed, no version number available
numpy: 1.12.1
scipy: 0.19.0
sklearn: 0.18.1
joblib: 0.11
decorator: 4.0.11
six: 1.10.0
resampy: 0.1.5

numpydoc: installed, no version number available
sphinx: 1.5.1
sphinx_rtd_theme: 0.2.4
sphinxcontrib.versioning: 2.2.1
matplotlib: 2.0.0
numba: 0.32.0
``````