Skip to content

Instantly share code, notes, and snippets.

@r9y9
Last active June 13, 2017 16:10
Show Gist options
  • Save r9y9/3d0c6a90dd155801c4c1 to your computer and use it in GitHub Desktop.
Save r9y9/3d0c6a90dd155801c4c1 to your computer and use it in GitHub Desktop.
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()
@r9y9
Copy link
Author

r9y9 commented May 8, 2015

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

@r9y9
Copy link
Author

r9y9 commented Jun 13, 2017

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:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
blas_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
lapack_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
blas_mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/home/ryuichi/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/home/ryuichi/anaconda3/include']
blas_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment