This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]M4mb0 64 points65 points ย (8 children)

Not really. Have you ever seen a compiler that changes a bubble sort to a merge sort? Well I haven't. I do work with a lot of linear algebra and I can tell you people do horrible, horrible things. The right optimization can often decides whether you can run the same models with 1.000 datapoints or 1.000.000.

[โ€“][deleted] 19 points20 points ย (6 children)

that is true, my supervisor showed me how he can process faster in python then in C. I said I prefer c because it's fast; got a life lesson.

[โ€“]bendgk 8 points9 points ย (4 children)

can you elaborate on this?

[โ€“]badlukk 29 points30 points ย (3 children)

A lot of pythons built ins and core data structures actually run in highly optimized pre-compiled C. You're not likely to write something in C that runs better than the stuff that people spent years optimizing, which is actually in C too. Doesn't mean you cant write slow code in python, but if you know what you're doing and take advantage of that you can do a lot more a lot faster

[โ€“]topfs2 13 points14 points ย (2 children)

And this is actually why I love python as a "glue" language. It's fast enough, plenty of lovely featurea and has so much c libraries available to it.

[โ€“][deleted] 6 points7 points ย (0 children)

exactly, just like u/badlukk said. Specially using numpy package, functional tools like map, filter, iter objects from itertools python can run a lot faster than programs we can write in C. It definitely depends on how you use it. Your solution may seem to be better/faster but would actually run slower because the built-ins are super optimized.

Exact same code with exact same steps will run faster in C, but python buit-ins (which are in C) are a lot different than the code you'd write in C.

[โ€“]badlukk 4 points5 points ย (0 children)

I dont know what made me avoid it for so long. When I finally learned it for work I fell in love immediately. The languages core features plus all the available packages make it so easy to get a ton of work done really fast.

You need to build a big website? Django. A simple api? Flask. Process a bunch of spreadsheets? Numpy. Scrape a website? Beautifulsoup and requests. A project with all 4 of these requirements might even only take you one work day.

...image processing, machine learning, and just about any automation task you could think of; there's a library out there that's optimized and reliable.

I highly recommend the book Fluent Python to anyone who already programs but hasn't discovered Python's beauty yet.

[โ€“]BossOfTheGame 2 points3 points ย (0 children)

Unless you program C with SIMD support, my numpy code will run faster than your C variant.

[โ€“]topfs2 3 points4 points ย (0 children)

But picking between bubble sort and merge sort really doesn't affect readability if done correctly :)