r/rust • syntect • Jun 15 '19

Comparing the Same Project in Rust, Haskell, C++, Python, Scala and OCaml

http://thume.ca/2019/04/29/comparing-compilers-in-rust-haskell-c-and-python/
261 Upvotes

45 comments sorted by

View all comments

Show parent comments

2

u/trishume syntect Jun 16 '19

No they still had to output assembly strings, there was just an extra step with a bunch of allocation in between. I didn’t do performance comparisons and they wouldn’t be very informative since the algorithms are all different.

26

u/link23 Jun 16 '19

they wouldn’t be very informative since the algorithms are all different.

That sounds like the interesting part to me, though. We'd get another dimension in which to measure the effects of the differing design decisions.

18

u/[deleted] Jun 16 '19

Precisely. I was sort of disappointed to see that only code size was considered (and it was no surprise that Python was the tersest of them all). I would have liked to see some performance benchmarks as well, especially considering that for real-world compilers, it's not so much the size of the compiler that's important as the performance/size of the generated code.

4

u/budgefrankly Jun 16 '19

Python isn’t that terse when you get down to it: it’s a primarily OOP, imperative language that borrowed list comprehensions from the functional folks. From what I’ve seen, particularly with folks using type hints, it’s about as verbose as Kotlin.

As an example, pattern matching and destructuring in Rust translates into a massive if-elif-else chain with mutable assignments in Python.

I think the programmer in question is just particularly adept at writing code, though perhaps only code that machines can read.

10

u/Khaare Jun 16 '19

Python gets a lot of its "terseness" from how it dispenses with ceremony (as all dynamic languages do), from how easy it is to manipulate standard collections, and from the batteries included philosophy. You can get a lot of mileage out of that in the right applications and with the right coding style. Of course, you don't always have the right application nor can afford that coding style, but for one-person projects you often can get pretty far with that.

Otherwise, if you structure your Python code like you would Java then all Python gives you is freedom from curly braces.

1

u/[deleted] Jun 16 '19

Yes, this is what I mean.

0

u/[deleted] Jun 16 '19

[deleted]

6

u/Leonidas_from_XIV Jun 16 '19

It is to add a dimension to the test. Because as it stands the only compared factor really is code size (and correctness to some degree). If you write a program your requirement is rarely "use as few lines as possible".

1

u/rebootyourbrainstem Jun 16 '19

Could you give some idea how much slower the Python implementation was compared to the others?

I'd expect it to be a different ballpark from the others, like at least 5-10x slower.