6 ms·
Python is a high-level interpreted language, and C/C++ are low-level (even compared to other) compiled languages. While you might be able to optimize your Pytho
by saghm 9y ago
Python is a high-level interpreted language, and C/C++ are low-level (even compared to other) compiled languages. While you might be able to optimize your Python code to run faster than it does now, it's never going to match the performance of C/C++, nor is it intended to.
Go will be a significant speedup over Python, but likely won't quite match the speed of C/C++ for most tasks. Then again, the ease of development in Go will likely be noticeably better than in C or C++. Rust could potentially match the speed of C++, but it's a much more complex language than Go, so it will take some time to master. (Personally, having spent a large amount of time programming in Rust, I find myself more productive than in Go due to the powerful abstractions present in the former and lacking in the latter, but conventional wisdom is that this won't be the case for most people, and it certainly won't be when you're first learning Rust).
EDIT: Anecdotally I've heard that D is a nice language, but I have no experience with it, so I can't comment on how productive it is or how fast D code will run.
- pjmlp 9y agoYou can easily get best of both worlds with Lisp derived languages.
- sythe2o0 9y agoIt's been my understanding that Lisp and its relatives aren't designed to compete against C for speed either. Is this wrong?
- pjmlp 9y agoC was designed on a PDP-11, a computer much more powerful than the mainframes where Lisp was already running since 10 years, so Lisp implementations were already quite good for most tasks by then. While C designers were trying to create UNIX at AT&T, Xerox PARC was busy creating Smalltalk, Interlisp-D and Mesa/Cedar. Other companies were creating Genera and the Connection Machine, In the end Worse is Better won, because the machines were too expensive for most pockets, normal developers could not grasp Lisp, mismanagement from those companies and UNIX was kind of cheap when comparing prices, with source code available almost for free (AT&T was prevented from selling it early on).
- steinuil 9y agoCommon Lisp has some very fast implementations (I think SBCL is the fastest) and it was designed to be a systems language. It can be optimized to be as fast as C.
- rifung 9y ago> It can be optimized to be as fast as C Sorry if dumb question but how is this possible when it's garbage collected? Now I really feel like I need to learn a Lisp though.. Is there a certain Lisp you would recommend that's practical enough I'd use it for projects? Racket?
- pjmlp 9y agoYou can start by reading about Genera and Interlisp-D https://en.wikipedia.org/wiki/Genera_(operating_system) https://en.wikipedia.org/wiki/Genera_(operating_system) https://www.ics.uci.edu/~andre/ics228s2006/teitelmanmasinter.pdf https://www.ics.uci.edu/~andre/ics228s2006/teitelmanmasinter... http://www.softwarepreservation.org/projects/LISP http://www.softwarepreservation.org/projects/LISP Just check the hardware capabilities of systems having Lisp 1.5 support, several years before C was created. Lisp is not only manipulating lists, it grew up to natively support all relevant data structures, including primitives to handle systems programming tasks. Regarding GC and systems programming, there are plenty of GC enabled systems programming languages, the main point is that they offer features to control the GC and also do stack and GC free allocation if required. Some examples would be Mesa/Cedar, Modula-2+, Modula-3, Oberon, Oberon-2, Oberon-07, Active Oberon, Component Pascal, Sing#, System C#, D
- flavio81 9y ago> Sorry if dumb question but how is this possible when it's garbage collected? On a big or complex system you end up at least doing one or both or two things: a. Having to manage many temporal (transient) objects in memory. Thus you end up doing some sort of garbage collector, either doing it yourself, or using the facilities provided by the languages, or a library. b. Allocating fixed big blocks of memory (such as arrays, or doing a "malloc") and then using this block of memory as your storage area, which then you manage. Usually on C programming you do (b), although you can also do (a), it is not so easy. Usually on Common Lisp programming you do (a) very easily, but you can also do (b) by allocating an array and a bit more stuff. It is not difficult, really.
- flavio81 9y ago"How to make Lisp go faster than C" (2006) http://www.iaeng.org/IJCS/issues_v32/issue_4/IJCS_32_4_19.pdf http://www.iaeng.org/IJCS/issues_v32/issue_4/IJCS_32_4_19.pd... And these figures aren't using the SBCL Lisp compiler which should currently be faster than the one cited. You are correct, it wasn't designed to compete against C. And it has a garbage collector. But make the right choices and a compiler like SBCL can produce surprisingly "clean" (optimized) machine language code.
- saghm 9y agoC compilers have presumably gotten faster since then as well, of course
- Keyframe 9y agoI like Lisp, though Scheme in particular. However, I have no idea where I would turn to in order to write an application with GUI that needs to be cross-platform and, possibly, derive a mobile version for iOS and Android from the same codebase.
- pjmlp 9y agoTo mocl https://wukix.com/mocl https://wukix.com/mocl
- saghm 9y agoGiven that GP said "cross-platform" and then separately "possible derive mobile", I'm guessing that only supporting OS X on the desktop might not be enough for them. That being said, I'd be very surprised if there weren't cross-platform desktop GUI libraries available for Common Lisp.
- Keyframe 9y agoI'd be shocked if WxWidgets weren't supported, maybe even Qt.
- Keyframe 9y agoInteresting, but premise seems to be that UI code should be done outside of Lisp. Whereas, at least in my experience, this is where most code and trouble lives.
- 0xdeadbeefbabe 9y ago> Go will be a significant speedup over Python, but likely won't quite match the speed of C/C++ for most tasks. Then again, the ease of development in Go will likely be noticeably better than in C or C++. In my experience, you don't mean: learn to make C and C++ development just as easy as Go development and enjoy the best of both worlds. I agree with you, but it seems illogical on the surface.
- deleted 9y ago[deleted]
- adrianN 9y agoJavascript is also high-level interpreted language, but it's much faster than Python. Python is pretty hard to optimize in a JIT (and it gets much less attention than Javascript).
- saghm 9y agoTrue, but it's also miles behind C/C++. While Python is arguably the slowest of the mainstream interpreted language, they're all orders of magnitude slower than C.
- new299 9y agoHmmm. I kind of expect them to be 1 or 2x slower. Maybe even a single order of magnitude... But Python seems often to be 100 or 1000x slower. For my applications this is kind of unfortunate.
- nindalf 9y ago> Go will be a significant speedup over Python, but likely won't quite match the speed of C/C++ for most tasks. Its true, Go won't match the speed of C, but it comes pretty damn close. Say you have 4 cores, 1 would be dedicated to GC and the other 3 would be executing your program. That sounds sub-optimal, meaning that a Go program could only be 75% as fast as an equivalent C program. But you have to wonder how many developers are capable of writing multi-threaded, correct C code. Go is simple to learn, lightning quick to compile and runs reasonably fast. By no means is it perfect, and it is not the tool I'd use for every task in front of me, but it is good enough for most tasks. I agree that Rust is the future in the low level space.
- vardump 9y ago> Say you have 4 cores, 1 would be dedicated to GC In my opinion, idiomatic golang is not that GC heavy. A slice (a bit like ArrayList) of structs can be a contiguous chunk of memory as opposed to array of object references, which requires allocating each object separately. There are an order of magnitude less allocated objects than in Java for example. (Perhaps the situation will change once Java gains value types in maybe Java 9).
- vardump 9y ago> Go...but likely won't quite match the speed of C/C++ for most tasks. Last I checked golang generated code 3 years ago, it was full of redundant instructions, most notably redundant range checks. Seemed to be about half as fast as equivalent C/C++ code. I believe golang can approach something like 80-95% of C/C++ performance once codegen is good.