Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Comparing AVL Trees in C++ and Haskell (izbicki.me)
14 points by CheriPai on Sept 15, 2014 | hide | past | favorite | 1 comment


> You might think that it is unfair to compare multithreaded Haskell against C++ that is not multithreaded. And you’re absolutely right! But let’s be honest, manually working with pthreads in C++ is quite the headache, but parallism in Haskell is super easy.

C++ has std::thread and it would be very simple to parallelize this program, so yes it is unfair. I also wonder just how optimized the C++ AVL library is when it contains "//Assignment 6" at the top of its header. The C++ program is also non-optimal in that it is doing 2x lookups for each insert, once for the insert and then another to increment the counter. I haven't investigated the Haskell to see if it does the same.

Another important point is that mutable single node data structures like AVL or red black trees provide a property that the Haskell data structure cannot: stable iterators. If you don't need this property then you can usually get better run-times by using a more cache efficient data-structure like a BTree.

This is a very biased comparison.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: