Oh cool, this is the one thing that I've actually contributed to base 
Julia! In this pull request <https://github.com/JuliaLang/julia/pull/10961> we 
found and fixed a type instability in the collect function. Julia v0.3 or 
v0.4 up until a few days ago will still suffer from this. You could write 
your own version of the function using the information in that pull request 
if you want the speed increase now (i.e. make a function called something 
like my_collect that reads like this 
<https://github.com/JuliaLang/julia/blob/63dac6dd531c87be9fa9e504f1afc050a838635b/base/array.jl#L255>),
 
or update to a newer version of 0.4-dev. My timings are 5 ms in Python 
2.7.8 and 2.7 ms in the latest Julia 0.4. 

Cheers,

Scott T

On Thursday, 30 April 2015 23:43:24 UTC+1, Ali Rezaee wrote:
>
> Dear all,
>
> I have a ported all my project from python to Julia. However, there is one 
> part of my code that I have not been able to optimize much. It is between 3 
> to 9 times slower than similar python code.
> Do you have any suggestions / explanations?
>
> Julia code:
> function collect_zip(a::Array=["a","b","c","d"],b::Array=[0.2,0.1,0.1,0.6
> ])
>   c = collect(zip(a,b))
> end
>
> collect_zip()
> @time for i in 1:10000; j= collect_zip();end # elapsed time: 0.089672328 
> seconds (9 MB allocated)
>
> Python code:
> def listzip(a = ["a","b","c","d"], b = [0.2,0.1,0.1,0.6]):
>     c = list(zip(a,b))
> a = timeit.timeit("listzip()","from __main__ import listzip",number=10000)
> print(a) # 0.0105497862674
>
> P.S: I need to convert the zip to an array because after that I need to 
> sort them.
>
> Thanks a lot,
>

Reply via email to