Yes, your example was necessary (for me). The final MWE
using PyCall
using BenchmarkTools
#I would like to be able to read the python snippet from a file like
# py_snippet=read("axpy.py")
#but for now I follow the PyCall example
py"""
def pyaxpy(y,x,a):
y+=a*x
"""
pyaxpy = py"pyaxpy"
function measure(n)
@show n
x,y,a=(rand(n),rand(n),1/3)
@btime py"pyaxpy"($y,$x,$a)
px,py,pa=map(PyObject,(x,y,a))
@btime py"pyaxpy"($py,$px,$pa)
@btime $pyaxpy($py,$px,$pa)
@btime pycall($pyaxpy, PyObject, $py,$px,$pa)
end
foreach(measure,(10^i for i in (1:4)))
and results:
n = 10
14.007 μs (23 allocations: 1.05 KiB)
12.474 μs (11 allocations: 400 bytes)
3.172 μs (4 allocations: 176 bytes)
1.526 μs (2 allocations: 48 bytes)
Thank you very much.
Do you know how to include the Python snippet from a file ?