# Topological sort (performance)

**URL:** <https://discourse.julialang.org/t/topological-sort-performance/17153>\
**Category:** Performance\
**Tags:** sort\
**Created:** [November 5, 2018, 4:27am UTC](https://discourse.julialang.org/t/topological-sort-performance/17153 "2018-11-05T04:27:55Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 7, 2018, 6:36am UTC](https://discourse.julialang.org/t/topological-sort-performance/17153/18 "2018-11-07T06:36:07Z")

</div>

> [@stevengj](#):
>
> but this is not an especially interesting comparison because continually allocating lots of dictionaries within inner loops is not how you would write optimized Julia code.

This is same interesting as to benchmarking recursive fibonacci because: “It is important to note that the benchmark codes are not written for absolute maximal performance. Instead, the benchmarks are written to test the performance of _identical algorithms and code patterns_ implemented in each language.” (Source: [Julia Micro-Benchmarks](https://julialang.org/benchmarks/)) .

ping @Sukera (our discussion [here](https://discourse.julialang.org/t/performance-problem-of-count/16873/13) ):

> [@Performance problem of count?](https://discourse.julialang.org/t/performance-problem-of-count/16873/12):
>
> Wouldn’t be usefult to propose then in “benchmark tips” to not use generators?

> [@Performance problem of count?](https://discourse.julialang.org/t/performance-problem-of-count/16873/13):
>
> No, not at all! Why have a language feature when you’re discouraged from using it?

We have now this competent answer:

> [@StefanKarpinski](#):
>
> Terminology aside, Python has heavily optimized this pattern because it’s a common way to implement things in Python. This is not a common way to write high performance code in Julia, and it could certainly be optimized further.

We have now these possibility in [Performance tips in doc](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-tips-1):  
a) not discourage people from using generator because “we have it” 😜  
b) admit that this code pattern is better implemented in python (\*) and add performance tip to not use it in performance critical part of code (this can be changed in future!)  
c) do as this is not happening.

(\*) we don’t need to say about python there it is enough to say that `generator` (cite:) “is not a common way to write high performance code in Julia”. And we could add this for sure to [doc: Noteworthy differences from Python](https://docs.julialang.org/en/v1/manual/noteworthy-differences/#Noteworthy-differences-from-Python-1) because it will bite many pythonistas trying to port their code!

---

_[View the full topic](https://discourse.julialang.org/t/topological-sort-performance/17153)._
