# PyCall minimal overhead

**URL:** https://discourse.julialang.org/t/pycall-minimal-overhead/41127
**Category:** Performance
**Created:** [June 10, 2020, 2:03pm UTC](https://discourse.julialang.org/t/pycall-minimal-overhead/41127 "2020-06-10T14:03:38Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [June 10, 2020, 4:29pm UTC](https://discourse.julialang.org/t/pycall-minimal-overhead/41127/8 "2020-06-10T16:29:05Z")

</div>

Yes, your example was necessary (for me). The final MWE

```julia
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:

```julia
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 ?

---

_[View the full topic](https://discourse.julialang.org/t/pycall-minimal-overhead/41127)._
