# Efficiency for calling Julia from python and purely run Julia

**URL:** <https://discourse.julialang.org/t/efficiency-for-calling-julia-from-python-and-purely-run-julia/81484>\
**Category:** General Usage\
**Created:** [May 23, 2022, 3:16am UTC](https://discourse.julialang.org/t/efficiency-for-calling-julia-from-python-and-purely-run-julia/81484 "2022-05-23T03:16:01Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Geositta](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@Geositta](https://discourse.julialang.org/u/Geositta)\
**Post date:** [May 23, 2022, 7:11am UTC](https://discourse.julialang.org/t/efficiency-for-calling-julia-from-python-and-purely-run-julia/81484/7 "2022-05-23T07:11:04Z")

</div>

Thank you so much for pointing out.

The motivation is, from I heard and some tests,

> [@Is there any way to optimize array additions and multiplications with transposes?](https://discourse.julialang.org/t/is-there-any-way-to-optimize-array-additions-and-multiplications-with-transposes/80268/12):
>
> I checked the following Python script import numpy as np import time n0=n1=n2=n3=30 A = np.random.random((n0,n1,n2,n3)) n\_loop = 100 start = time.time() for i in range(n\_loop): B = np.add( 0.1\*A, 0.2\*np.transpose(A,(1,0,2,3)) ) end = time.time() print((end - start)/n\_loop \* 1000, " ms") against Julia’s using BenchmarkTools, LoopVectorization, Tullio function test1(A) B = similar(A) for i in 1:size(A,1), j in 1:size(A,2) # B[i,j,:,:] = 0.1\*A[i,j,:,:] + 0.2\*A[i,j,:,:]' …

> TensorOperations.jl is often the fastest way to do `permutedims` on larger arrays. It has a smarter cache-friendly blocking algorithm than the one in Base. But how much this matters of course depends on size & permutation.

My goal involves a series of array additions and permutations, it is complicated to optimize memory cache to improve the performance in Numpy/Fortran. `TensorOperations.jl` has some feature on it.

In one example in the above link, the timing from python is `4.956309795379639 ms` and in julia is ` 2.585 ms (21 allocations: 6.18 MiB)`, about a factor of 2 better. I observed a similar pattern in other cases.

---

_[View the full topic](https://discourse.julialang.org/t/efficiency-for-calling-julia-from-python-and-purely-run-julia/81484)._
