Skip to content

Instantly share code, notes, and snippets.

View standy66's full-sized avatar

Andrew Stepanov standy66

  • Quantum Light Capital
  • London, United Kingdom
View GitHub Profile
@standy66
standy66 / c_extension_call_overhead.py
Created March 28, 2018 21:29
PyPy vs CPython extension call overhead
"""
Original code: https://gist.github.com/brentp/7e173302952b210aeaf3
Compare speed of a cython wrapper vs a cffi wrapper to the same underlying
C-code with a fast function and a longer-running function.
This should run anywhere that has cffi and cython installed.
$ python3.6 -V
Python 3.6.2 (default, Jul 17 2017, 16:44:45)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
OpenSSL 1.0.2k 26 Jan 2017
built on: reproducible build, date unspecified
options:bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) aes(partial) idea(int) blowfish(ptr)
compiler: arm-brcm-linux-uclibcgnueabi-gcc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -ffunction-sections -fdata-sections -O3 -Wall -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DBSAES_ASM -DGHASH_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 0.00 0.00 0.00 0.00 0.00
mdc2 2197.96k 2339.09k 2417.00k 2428.89k 2446.42k
md4 11506.71k 38225.13k 93329.90k 151152.50k 184607.98k
md5 8904.43k 27768.25k 67982.16k 104957.58k 124709.36k
OpenSSL 1.0.2g 1 Mar 2016
built on: reproducible build, date unspecified
options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: cc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 0.00 0.00 0.00 0.00 0.00
mdc2 0.00 0.00 0.00 0.00 0.00
md4 127034.79k 377429.23k 859238.66k 1
@standy66
standy66 / vpio-macos-example.cc
Created January 21, 2019 09:28
Voice-Processing I/O MacOS example
#include <iostream>
#include <cmath>
#include <fstream>
#include <AudioToolbox/AudioToolbox.h>
// Files with raw float32 data
std::ifstream ifile("ifile.f32");
std::ofstream file("file.f32");
@standy66
standy66 / audio_from_spectrogram.py
Created July 12, 2017 14:47
A small snippet that helps reconstruct audio from spectrogram in Python
from scipy.signal import stft, istft
def reconstruct(spectrogram, sample_rate, nperseg, iters=100):
length = istft(spectrogram, sample_rate, nperseg=nperseg)[1].shape[0]
x = np.random.normal(size=length)
for i in range(iters):
# Code based on the answer here: https://dsp.stackexchange.com/a/3410
X = stft(x, sample_rate, nperseg=nperseg)[2]
Z = spectrogram * np.exp(np.angle(X) * 1j)
x = istft(Z, sample_rate, nperseg=nperseg)[1]